Pedro Chagas
asked on
Php - Remove sets with charactes less-than and greater-than up to 3 characters
Hi E's,
I need a solution much more effective than my solution.
In practice, if I have this string:
The best regards,
JC
I need a solution much more effective than my solution.
In practice, if I have this string:
$str = "<span>this is text </span> to <i>show</i> <AB2>what</AB2> I need <E3>to</E3> continue";
and I need to remove <x> <xx> <xxx> (from 1 to 3 characters, include numbers), like this:$str = "<span>this is text </span> to show what I need to continue";
Before I come here, I try this solution, too archaic, and I think one simple Regular Expression resolve the problem:$arr_guarda = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "z", "y", "w", "k", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "Z", "W", "Y", "K", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", " ");
$arr_guarda2 = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "z", "y", "w", "k", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "Z", "W", "Y", "K", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
foreach($arr_guarda2 as $valora){
$valor1 = $valora;
foreach($arr_guarda as $valorb){
$valor2 = $valorb;
foreach($arr_guarda as $valorc){
$valor3 = $valorc;
$valor3 = trim($valor3);
$arr_tudo[] = $valor1 . $valor2 . $valor3;
}
}
}
foreach($arr_tudo as $valor){
$final = "<" . $valor . ">";
$res = str_replace(array($final, '&', '"'), ' ', $res);
}
The solution work, but is not the best solution, so I need help.The best regards,
JC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.