Forum Moderators: coopster

Message Too Old, No Replies

how to use stripslashes(str replace in while looping

         

Shanee

6:35 am on Aug 26, 2006 (gmt 0)

10+ Year Member



how to use <?php echo stripslashes(str_replace('+', '-', urlencode($title)));?> in while looping?
here is the example of my script

<?php
$sql = "select * from jokes order by jokeid desc limit 10";

$result = mysql_query($sql ,$db);

if ($myrow = mysql_fetch_array($result)) {

do {
printf("<a href=%s/%s.php>%s</a>", $myrow["jokeid"], $myrow["joke-title"], $myrow["jokes-name"]);

} while ($myrow = mysql_fetch_array($result));

}

?>
i want to replace the jokes-title's spaces with dash, for example jokes blah blah to jokes-blah-blah
Thanks

smatts9

6:44 am on Aug 26, 2006 (gmt 0)

10+ Year Member



Try preg_replace,

<?php
$string = 'joke title blah';
$pattern = '/ /i';
$replacement = '-';
echo preg_replace($pattern, $replacement, $string);
?>

Shanee

7:40 pm on Aug 26, 2006 (gmt 0)

10+ Year Member



Dear smatts9

The Problem is How to use preg_replace in Looping

Thanks

supermoi

10:14 pm on Aug 26, 2006 (gmt 0)

10+ Year Member



You can place it in a loop and loop through it as many times as you want but the string will only be chaged in the first iteration.