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: PHP, Source Code, Webmaster