Reputation: 75
So I had this function to get between 2 values in a string
function get_string_between2($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
Then, in order to get support for a newer feature, I upgraded to 5.5. Now my function doesn't work. Are there any other ways to do this that are confirmed to work in this new version?
Upvotes: 0
Views: 162
Reputation: 1536
You should test the result of strpos
for Boolean FALSE
before proceeding in your code; testing $ini == 0
is not sufficient.
See the big warning here: http://php.net/manual/en/function.strpos.php
Upvotes: 1