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. 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 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. 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
Archived
This topic is now archived and is closed to further replies.