young_coder Posted September 9, 2010 Share Posted September 9, 2010 Dear all, I want to remove all lines less than 3 words longs so I can stuff the rest into a db. Can somebody help me? Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/212994-remove-all-lines-less-than-3-words-longs/ Share on other sites More sharing options...
fortnox007 Posted September 9, 2010 Share Posted September 9, 2010 could you give an example? And i am almost sure you need preg_replace for this Quote Link to comment https://forums.phpfreaks.com/topic/212994-remove-all-lines-less-than-3-words-longs/#findComment-1109310 Share on other sites More sharing options...
litebearer Posted September 9, 2010 Share Posted September 9, 2010 Hmmm explode each line using space as delim - if elements more than 3, keep. if elements 3 or less discard Quote Link to comment https://forums.phpfreaks.com/topic/212994-remove-all-lines-less-than-3-words-longs/#findComment-1109313 Share on other sites More sharing options...
Alex Posted September 9, 2010 Share Posted September 9, 2010 $text =<<<TEXT line containing more than three words less than three words on the previous two lines TEXT; $split = explode("\n", $text); foreach($split as $key => $line) { if(str_word_count($line, 0) < 3) { unset($split[$key]); } } echo implode("\n", $split); str_word_count Quote Link to comment https://forums.phpfreaks.com/topic/212994-remove-all-lines-less-than-3-words-longs/#findComment-1109317 Share on other sites More sharing options...
young_coder Posted September 9, 2010 Author Share Posted September 9, 2010 Yes.. this working and this is what I needed.. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/212994-remove-all-lines-less-than-3-words-longs/#findComment-1109322 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.