ballhogjoni Posted July 11, 2008 Share Posted July 11, 2008 I want to strip a string of all the characters after a certain charater. example: I have a string 'this is a string&more=this is some more stuff' based off of the string above I want to trim or delete all the characters after the &. So my output would just be 'this is a string'. Link to comment https://forums.phpfreaks.com/topic/114269-solved-what-function-would-you-use-to-do-this/ Share on other sites More sharing options...
thebadbad Posted July 11, 2008 Share Posted July 11, 2008 If you want to return the part of the string up to the first occurrence of an ampersand, this will work: <?php $str = 'this is a string&more=this is some more stuff'; $str = substr($str, 0, strpos($str, '&')); echo $str; ?> Link to comment https://forums.phpfreaks.com/topic/114269-solved-what-function-would-you-use-to-do-this/#findComment-587562 Share on other sites More sharing options...
rmbarnes82 Posted July 11, 2008 Share Posted July 11, 2008 <?php $string = 'this is a string&more=this is some more stuff'; if(($pos = strpos($string, '&')) !== false) $string = substr($string, 0, $pos); Link to comment https://forums.phpfreaks.com/topic/114269-solved-what-function-would-you-use-to-do-this/#findComment-587564 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2008 Share Posted July 11, 2008 Simply use the explode() function: <?php $string = 'this is a string&more=this is some more stuff'; list($string) = explode('&',$string); ?> Ken Link to comment https://forums.phpfreaks.com/topic/114269-solved-what-function-would-you-use-to-do-this/#findComment-587626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.