I'm modifying a string and want to find the last position of the occurence of a substring such as "[TEST". This is always followed somewhere in the string with the substring "[/TEST]". I've used strrpos($string, "[TEST") and strrchar($string, "[TEST"). Each time I get the position of the "[/TEST]" string which follows it. I imagine this has something to do with regular expressions possibly... I just want to deal with strings here though and don't seem to be able to... Thanks, James
If you have php 5.0 use strripos() If not use this... function strripos($haystack, $needle) { $haystack = strtolower($haystack); //remove this for case-sensitivity $needle = strtolower($needle); //remove this for case-sensitivity $tmp = strpos(strrev($haystack),strrev($needle)); if ($tmp === false) return false; else return strlen($haystack) - ($tmp + strlen($needle)-1) - 1; } PHP: like this: echo strripos($string, "[TEST");