Is there a better way to do below? (without the possibility of a fatal error)
function remove_before($needle,$haystack){ return substr(strstr($haystack,$needle),strlen($needle)); }
like strstr ($ haystack, $ needle), but without a needle in the returned string, and I might also ask if this could be improved ...
function remove_after($needle,$haystack){ return substr($haystack, 0, strrpos($haystack, $needle)); }
note that delete the line after the strip after the last occurrence of the needle and delete before rinsing the line before the first occurrence of the needle.
edit Example:
$needle = '@@'; $haystack = 'one@@two@@three'; remove_after($needle,$haystack);//returns one@@two remove_before($needle,$haystack)://returns two@@three
edit I will leave it here so that other people can refer.
string php
Timo Huovinen
source share