Forum Moderators: coopster

Message Too Old, No Replies

php text

         

electricocean

5:14 am on Jun 27, 2005 (gmt 0)

10+ Year Member



Hi, I was wondeing if there is a way to add a pipe character " ¦ " in between words if it's NOT the begining or the last word

like so: my ¦ name ¦ is ¦ bob // the pipe character " ¦ " is inbetween every word xcept the begining and last word

thanks,
electricocean

mcibor

8:19 am on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if the words are in an array, trhen just implode it:

$words = array("my", "name", "is", "bob");
$with_pipe = implode("¦", $words);

If the words are in a string, then you can use str_replace

$words = "My name is Bob";
$with_pipe = str_replace(" ", "¦", $words);

Hope this helps!
Michal

mcibor

8:50 am on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or if you get the words from db then:
$with_pipe = ""; //clear the var
while($row = mysql_fetch_array($query)) {
$with_pipe .= $row["word"]."¦";//Create string with fields separated by a pipe
}
$with_pipe = substr($with_pipe, 0, -1);//get rid of last pipe

Best regards
Michal Cibor

PS. Moderator, what happened with edit? I tried to edit the post after a minute and it was already too late.