robcrozier Posted March 9, 2007 Share Posted March 9, 2007 hi, what I'm trying to do is read a string until i come across a certain character and then chop the rest of the string off so i am only left with the first half up to the character that i searched for. Another thing though, i may need to search for the second or third occurrence of this character before truncating the string. Can this be done too? cheers! Quote Link to comment https://forums.phpfreaks.com/topic/41938-finding-characters-in-a-string/ Share on other sites More sharing options...
Orio Posted March 9, 2007 Share Posted March 9, 2007 You got two simple options (and probably much more): <?php function str_cut1($string, $char) { return substr($string, 0, strpos($char)); } function str_cut2($string, $char); { $temp = explode($char, $string); return $temp[0]; } ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/41938-finding-characters-in-a-string/#findComment-203334 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.