20070830

Simple substring-before function in php


function substring_before($haystack, $needle)
{
if ($i=stripos($haystack, $needle))
{// Needle found, return from start to needle
return(substr($haystack, 0, $i));
}
else
{// Needle not found
return $haystack;
}
}


Really need an explanation ?

2 comentarios:

  1. Anónimo5:05 a. m.

    Muy clara tu funcion

    ResponderEliminar
  2. Anónimo1:06 a. m.

    esta funcion lo hace, no se si no estaba antes

    http://us2.php.net/manual/en/function.strstr.php

    ResponderEliminar