In PHP i'm trying to cut out a specific word with the substr
function.
The way I am doin this is:
Check if the word actually exists in the string:
$haystack = "/home/{i:id}/{s:aString}"; $needle = "{i:id}"; if ($position = strpos($haystack, $needle)) {...}
Calculate the last character in the word by using
substr
$haystack = "/home/{i:id}/{s:aString}"; $needle = "{i:id}"; if ($position = strpos($haystack, $needle)) { $rpos = strpos($haystack, substr($needle, -1), $position); ... }
Print out the word by using
substr
again$haystack = "/home/{i:id}/{s:aString}"; $needle = "{i:id}"; if ($position = strpos($haystack, $needle)) { $rpos = strpos($haystack, substr($needle, -1), $position); echo substr($haystack, $position, $rpos); }
When running this piece of code, it strips the whole word, but stops way to late, it also takes 5 characters of the remainder of the string.
How do I fix this substr so it will only take the word i'm looking for?