How do I do this?

Discussion in 'PHP' started by GFX^^, Mar 15, 2007.

  1. #1
    I want to use the variable used in the title for the url, what I need is to count spaces and make them be dashes on the url, for example:

    Title is: How to make this
    Url should be: how-to-make-this.html

    How is it done?

    Thanks!
     
    GFX^^, Mar 15, 2007 IP
  2. stugs

    stugs Peon

    Messages:
    157
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $url = ereg_replace(" ","-",$title).".html";
     
    stugs, Mar 15, 2007 IP
  3. GFX^^

    GFX^^ Well-Known Member

    Messages:
    1,421
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    168
    #3
    Would u mind explaining me a bit how that works and how to use it in a link function?
     
    GFX^^, Mar 15, 2007 IP
  4. Ryandarin

    Ryandarin Peon

    Messages:
    66
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $url = ereg_replace(" ","-",$title).".html";

    What this does is searches for " " or spaces in $title, and changes them into a -
    So say
    $title='How to make this';
    $url = ereg_replace(" ","-",$title).".html";
    print $url;
    Code (markup):
    Should output How-to-make-this.html

    If you want to learn more, read this http://us3.php.net/manual/en/function.ereg-replace.php
     
    Ryandarin, Mar 15, 2007 IP
    GFX^^ likes this.
  5. GFX^^

    GFX^^ Well-Known Member

    Messages:
    1,421
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    168
    #5
    and how can I create dinamicaly how-to-make-this.html and put dinamycally some info ito it
     
    GFX^^, Mar 15, 2007 IP
  6. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #6
    if you mean to use it in a URL , You need the MOD_REWRITE Using the .htaccess ...
     
    commandos, Mar 15, 2007 IP
  7. GFX^^

    GFX^^ Well-Known Member

    Messages:
    1,421
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    168
    #7
    and how can I do that?
     
    GFX^^, Mar 15, 2007 IP
  8. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
  9. GFX^^

    GFX^^ Well-Known Member

    Messages:
    1,421
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    168
    #9
    already read that, but cant found how do I do this :D
     
    GFX^^, Mar 15, 2007 IP
  10. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #10
    also this could help

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

    then in htaccess

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


    Not sure if this will work , need a lot of tests for those things before it works ....
     
    commandos, Mar 15, 2007 IP
  11. ArtInt

    ArtInt Active Member

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #11
    ArtInt, Mar 16, 2007 IP