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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!