Why doesn't this work?
<?php
function GetBetween($var1="",$var2="",$pool) {
$temp1 = strpos($pool,$var1)+strlen($var1);
$result = substr($pool,$temp1,strlen($pool));
$dd=strpos($result,$var2);
if($dd == 0) {
$dd = strlen($result);
}
return substr($result,0,$dd);
}
$str = "[id]159828[/id][name][/name]";
$str = GetBetween("[name]","[/name]",$str);
echo $str;
?>
Returns:
[/name]
Works fine if there is something in there. I need it to return NOTHING if its not found.
Thanks!
$ddis first equal to 0 and then changed to be the length of the result. This makes your final callsubstr($result,0,7). If you have a value between the name brackets$ddis never set to 0 and the secondary assignment does not happen. Get rid of theif($dd == 0)...block.$var1and$var2if$poolis a required parameter ofGetBetween(). Put$poolas the first parameter if you want to make the others optional.