Remove spaces from dynamic url's

Discussion in 'PHP' started by malc, Jun 23, 2009.

  1. #1
    First time using mod_rewrite and would really appreciate some help.

    I am using:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)\.html$ searchresult.php?cat_id=$2[L]
    RewriteRule ^madeupword/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ article.php?art_id=$2[L]
    Code (markup):
    This make the links work like this:
    [url]http://www.mysite.com/Pasta-articles/24.html[/url]
    [url]http://www.mysite.com/madeupword/How-to-pasta/581.html[/url]
    Code (markup):
    This seems to work fine but the problem is, my url's are generated dynamically and for me to change them to static links there are spaces between the words.
    So the static link looks like this:
    [url]http://www.mysite.com/Pasta%20articles/24.html[/url]
    Code (markup):
    Instead of this:
    [url]http://www.mysite.com/Pasta-articles/24.html[/url]
    Code (markup):
    How can I change this code to replace a space(%20) with a dash(-)?
    <a href="madeupword/<?php echo $artrow_jok["art_title"]; ?>/<?php echo $artrow_jok["art_id"]; ?>.html"><?php echo $artrow_jok["art_title"]; ?></a> 
    Code (markup):

     
    malc, Jun 23, 2009 IP
  2. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <a href="madeupword/<?php echo str_replace(' ','-',str_replace('%20','-',$artrow_jok["art_title"])); ?>/<?php echo $artrow_jok["art_id"]; ?>.html"><?php echo $artrow_jok["art_title"]; ?></a>
    PHP:
     
    emed, Jun 23, 2009 IP
  3. malc

    malc Peon

    Messages:
    129
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Excellent!!! Thank you very very much :)
    Does the rest of the .htacces content look ok to you? I have no idea why it even works, I got most of that from other people's examples.
     
    malc, Jun 23, 2009 IP
  4. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    im not a htaccess expert, but it look ok to me, if it work dont touch it :)
     
    emed, Jun 24, 2009 IP