Silvar Posted January 22, 2013 Share Posted January 22, 2013 Example: If I got a variable called $description. When it finds the sentence: "I hate this part", it should stop and only print/echo the text from before that sentence. But how? I'm not familiar with this/can't figure it out. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/273503-only-print-text-from-variable-before-defined-text-string/ Share on other sites More sharing options...
premiso Posted January 22, 2013 Share Posted January 22, 2013 $pos = strpos($description, 'I hate this part'); if ($pos !== false) { $firstpart = substr($description, 0, $pos); }else { echo 'Section was not found'; } echo $firstpart; Using a mixture of substr and strpos Quote Link to comment https://forums.phpfreaks.com/topic/273503-only-print-text-from-variable-before-defined-text-string/#findComment-1407568 Share on other sites More sharing options...
Silvar Posted January 22, 2013 Author Share Posted January 22, 2013 Thank you very much for your fast reply. Quote Link to comment https://forums.phpfreaks.com/topic/273503-only-print-text-from-variable-before-defined-text-string/#findComment-1407570 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.