Jeffro Posted April 29, 2011 Share Posted April 29, 2011 I have several lines of text formatted as such: title text – some more text blah blah blah How do I delete everything after title text from every line ( the and ndash and after)? Thanks! Link to comment https://forums.phpfreaks.com/topic/235057-how-do-i-get-rid-of-this-extra-text/ Share on other sites More sharing options...
Pikachu2000 Posted April 29, 2011 Share Posted April 29, 2011 Is the format always the same, with the literal '–' in it? $str = "[text to keep] –' [text to remove]"; $new = trim(substr($str, 0, strpos($str, '–'))); echo $new; // returns "[text to keep]" Link to comment https://forums.phpfreaks.com/topic/235057-how-do-i-get-rid-of-this-extra-text/#findComment-1208022 Share on other sites More sharing options...
Jeffro Posted April 29, 2011 Author Share Posted April 29, 2011 Is the format always the same, with the literal '–' in it? $str = "[text to keep] –' [text to remove]"; $new = trim(substr($str, 0, strpos($str, '–'))); echo $new; // returns "[text to keep]" Many thanks. Worked perfectly! Link to comment https://forums.phpfreaks.com/topic/235057-how-do-i-get-rid-of-this-extra-text/#findComment-1208237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.