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
Cutting up strings into seperate strings
Moderator: General Moderators
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Perhaps something like this?
$needle = the string you are looking for
$haystack = the large string that MIGHT contain the needle
$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;
}