Dale_G Posted November 10, 2008 Share Posted November 10, 2008 String = 'hello!howare!yo!u?'; Look for the first occurrence of x, which in this case is '!', and then return the first section prior to x, which in this case would be 'hello'. How would that be done? Link to comment https://forums.phpfreaks.com/topic/132191-solved-return-string-contents-prior-to-x/ Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 couple different ways...here is one: $string = 'hello!howare!yo!u?'; $part = substr($string,0,strstr($string,'!')-1); Link to comment https://forums.phpfreaks.com/topic/132191-solved-return-string-contents-prior-to-x/#findComment-687045 Share on other sites More sharing options...
effigy Posted November 10, 2008 Share Posted November 10, 2008 <pre> <?php $str = 'hello!howare!yo!u?'; echo substr($str, 0, strpos($str, '!')); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/132191-solved-return-string-contents-prior-to-x/#findComment-687047 Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 <pre> <?php $str = 'hello!howare!yo!u?'; echo substr($str, 0, strpos($str, '!')); ?> </pre> yeah...my bad...no minus 1 Link to comment https://forums.phpfreaks.com/topic/132191-solved-return-string-contents-prior-to-x/#findComment-687056 Share on other sites More sharing options...
Dale_G Posted November 10, 2008 Author Share Posted November 10, 2008 Thanks! Link to comment https://forums.phpfreaks.com/topic/132191-solved-return-string-contents-prior-to-x/#findComment-687062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.