Jalz Posted February 21, 2010 Share Posted February 21, 2010 Hi, Hoping someone can help me please. I have text in a variable called $news similar to this in my news article: More than 60 senior economists have signed two open letters that back the chancellor's decision to delay government spending cuts until 2011. <img width="300" height="225" alt="" src="/images/Creek.jpg" /> The letters say that any measures to trim the budget deficit this year could pull the country back into recession. They are a riposte to the 20 economists who backed the Conservatives' call for cuts this year in the Sunday Times. Those economists had argued a lack of a credible plan threatened to push up interest rates and undermine recovery. What is the best way to remove any references to images from the article (and there maybe more than one). I would also like to store 200 words of the article in a news_summary field. I have used substr($News_row->getField('News'),0,200) command but thats only gets the first 200 characters and more than not chops my text in awkward places. Any help would be much appreciated. May Thanks Jalz Link to comment https://forums.phpfreaks.com/topic/192766-need-help-removing-text-values-and-limit-the-string-to-200-words/ Share on other sites More sharing options...
Catfish Posted February 21, 2010 Share Posted February 21, 2010 remove image tags: replace <img(any number of characters [ungreedily])/> with nothing in $string. $string = preg_replace('/<img.*\/>/U', '', $string); outputting first 200 words only, take a look at http://au.php.net/manual/en/function.str-word-count.php str_word_count() you can get the words of the string returned 1 word per key in an array, then you could use a for() loop up to 200 (or any number) times to build a string with 200 words. Link to comment https://forums.phpfreaks.com/topic/192766-need-help-removing-text-values-and-limit-the-string-to-200-words/#findComment-1015451 Share on other sites More sharing options...
Jalz Posted February 21, 2010 Author Share Posted February 21, 2010 Hi Catfish, Thanks for the help, that works Link to comment https://forums.phpfreaks.com/topic/192766-need-help-removing-text-values-and-limit-the-string-to-200-words/#findComment-1015824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.