Let's make this life Easy, as well as you can
Mengulas berbagai cerita kehidupan mulai dari tradisi hingga teknologi, tips, solusi, informasi, internet, pekerjaan, hiburan, Kesehatan, mitos, fakta, klenik, unik bahkan mistik yang diulas berdasarkan pengalaman serta dari berbagai referensi, semoga bermanfaat
Tired to find a way about how to eliminate, remove or delete words on string less than certain count in PHP?
someone say "I want to delete a words in strings where less than 3 character", or "what the best simple way to remove words less than two character in string".

Let me guess, may be you will used preg_replace like bellow to solve this problem?

$replaced = preg_replace('~\b[a-z]{1,2}\b\~', '', $yourstring);
$replaced = preg_replace('~\b[a-z]{1,2}\b\s*~', '', $yourstring);
preg_replace('/(\b.{1,2}\s)/','',$your_string);


Wich one will u use?  because someone say its work, and the others had say Not absolutely works, also Me have considered that way is not realy works.

PHP - How to remove, eliminate or delete words less than 3 character in string

I try with another way to fix this and I use EXPLODE, and STRLEN to the PHP script. example bellow:

<?php
$input='I try with another way to fix this and I use explode';
$pick=explode(' ', $input);
$newinput='';
foreach($pick as $words) {

if(strlen($words) <= 3) {
} else {

$newinput.=$words.' ';
}
}

//you can use result as or for new string
echo $newinput;
?>


Input : I try with another way to fix this and I use explode
Result : with another this explode
Eliminate Words less than 3 character : I, try, way, to, fix, and, I, use

Happy coding.

Labels: , ,



| Cari How to remove words less than certain count di : AOL | Ask | Bing | DuckDuckGo | Microsoft | Google | ixquick | Yahoo | Yandex | Yippy | MySearch