Forum Moderators: coopster

Message Too Old, No Replies

Mod Rewrite URL problems

Mod Rewrite URL problems

         

aspkin

7:47 am on Aug 25, 2006 (gmt 0)

10+ Year Member



Okay, so I created my .htaccess code and its working on my server, the only thing is my urls all have plus signs as spaces.. exp.

[somesite.com...]

How do I change this to - signs?

I know this is a php topic, but hold on I'll explain...

here is my .htaccess coding which is working..

RewriteEngine on

RewriteRule ^(.+)Article([0-9]+)\.html(/)?$ articleDetail.php?id=$2&title=$1

RewriteRule ^(.+)\.html(/)?$ $1.php

and here is my php code for the urls

<a href="<?php echo stripslashes(urlencode($title));?>+Article<?php echo $id?>.html"><?php echo stripslashes($title);?>...</a>

I'm fairly sure its nothing to do with the htaccess coding... but the php coding.. which I had a friend help me with.. but he doesnt know how to fix it..

Any advise is deeply appreciated,

Regards,

barns101

10:34 am on Aug 25, 2006 (gmt 0)

10+ Year Member



urlencode($title)

That bit will change any spaces into + symbols. If you want the URL to be URLEncoded, but with - instead of +, you could use this to change the symbols after it's been URLEncoded:


<?php echo stripslashes(str_replace('+', '-', urlencode($title)));?>

Shanee

1:05 pm on Aug 25, 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

aspkin

7:22 pm on Aug 25, 2006 (gmt 0)

10+ Year Member



Great! Thanks alot it worked!

My code for anyone else with this problem.

<a href="<?php echo stripslashes(str_replace('+', '-', urlencode($title)));?>-Article<?php echo $id?>.html"><?php echo stripslashes($title);?>...</a>