Page 1 of 1
Cutting up strings into seperate strings
Posted: Mon Jul 05, 2004 6:01 am
by dave_c00
Once i have got a string i would like to check the string to see if it has a certain word at the end of it. For example, if the string read in is 124565david. I would like to be able to take the david off the end..
Can anyone help .?
Thanks
Dave
Posted: Mon Jul 05, 2004 6:48 am
by litebearer
Perhaps something like this?
$needle = the string you are looking for
$haystack = the large string that MIGHT contain the needle
Code: Select all
$off_set = strlen($needle);
$whole = strlen($haystack);
$front = $whole - $off_set;
$tail = substr($haystack, $needle, ($off_set * (-1)));
if ($tail == $needle) {
// $needle was found at the end of the string
$beg_string = substr($haystack, 0, $front);
} else {
'' $needle was not found at the end
$beg_string = $haystack;
}
Posted: Mon Jul 05, 2004 7:04 am
by m3mn0n
Take a look at the Manual.
There is an entire section on string manipulation.
*see my signature for link*