March 28, 2011
str_replace “|” using php
Question by Jean
I want to insert "|"
in place of space " "
using str_replace
, but when I use it
str_replace("|", " ", $word);
All space between the words were deleted. Any help?
— The code
$word=explode(" ",$FromForm);
$word_count - str_word_count($_post['xxx'];
for($i=0;$i<=$word_count;$i++) {
echo str_replace("|"," ",$word[$i]);
//it echos fine without the string replace
}
Answer by Starx
I think you got the function the wrong way, if you are trying to replace certain text with |
, then you have to do something like this.
str_replace(" ","|",$word);
UPDATE
Since you exploded $FromForm by " "
, there will be nothing to replace by str_replace later on.