Char 'Space' b/w URL

Discussion in 'PHP' started by aleale, Dec 12, 2011.

  1. #1
    I am generating URL through 'fopen' when a new page created i am using the URL as the title of that page which i am inserting when user enters a title..

    Now the issue is if user enters multi words title then the URL got space after every word which looks very unprofessional..

    kindly help me to resolve this issue, what can i do to resolve this problem..

    Thanks in advance...
     
    aleale, Dec 12, 2011 IP
  2. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #2
    You could replace spaces with underscores:

    str_replace(" ", "_", $str);
    PHP:
     
    mfscripts, Dec 12, 2011 IP
  3. aleale

    aleale Well-Known Member

    Messages:
    1,453
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #3
    i am using this but its not working actually,

    my code is :

    $pagename = $_POST['title'].'.php';
    str_replace(" ", "_", $pagename);
     
    aleale, Dec 12, 2011 IP
  4. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #4
    You'll need to capture the result of str_replace. Try:

    $pagename = $_POST['title'].'.php';
    $pagename = str_replace(" ", "_", $pagename);
    PHP:
     
    mfscripts, Dec 12, 2011 IP
  5. aleale

    aleale Well-Known Member

    Messages:
    1,453
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #5
    A very very thanks to you... its working now.... Thank you very much...
     
    aleale, Dec 12, 2011 IP