PHP String Crop


Useful little function that finds and returns a chunk of a string between point A and point B..

function crop( $d='', $b='', $e='' )
{ return substr( $d, strpos( $d, $b )+strlen( $b ), strpos( $d, $e, strpos( $d, $b ) )-strpos( $d, $b )-strlen( $b ) ); }


$str = "some random STRING with some
html in it.";
echo crop( $str, '
', '' );

// should output "html"

Comments