str_replace just returns caps
-
30-09-2019 - |
Question
i have a lil problem here..i'm using str_replace
to replace the most common words..and for some reason its replacing every letter except caps.
for example..if i had the code below
$str ="Fat string of Text.";
$commonwords = array('fat','of','random');
$cleantext = str_replace($commonwords,'',$str);
echo $cleantext;
it would echo.. F T
any ideas what i did wrong.. thanks in advance
and oh..i tried str_ireplace
.. but nothing
Solution
This echos "Fat string Text".
Your PHP installation may be wrong or your posted code that does not exactly match the program you are running
Also, str_ireplace
echos "string Text".
OTHER TIPS
Can't reproduce that on PHP 5.3.3. I get:
php > $str ="Fat string of Text.";
php > $commonwords = array('fat','of','random');
php > $cleantext = str_replace($commonwords,'',$str);
php > echo $cleantext;
Fat string Text.
php > $cleantext = str_ireplace($commonwords,'',$str);
php > echo $cleantext;
string Text.
as expected.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow