1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP/MySQL Question

Discussion in 'PHP' started by hightide13, Dec 29, 2004.

  1. #1
    I have a site where I use PHP to display links based on info in a MySQL database:

    ie.
    <a href=/$statewords/$id.php><b>$name</b></a>

    where $statewords is the name of a State here in the US.

    My problem is that when I have a record with a space in it ("New York' for example) the link doesnt work right. It would show something like this:
    www.mysite.com/New instead of www.mysite.com/New%York/123.php
    Right now I have just taken the space out of the record.
    SEMrush
    How can I get the links to work correctly without putting % in the MySQL record or without deleting spaces all-together (NewYork)...

    If you need better examples I can show you the URL.
    Thanks!
     
    hightide13, Dec 29, 2004 IP
    SEMrush
  2. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I use under_scores " _ " they fill the gap and almost blend into the link.
     
    mushroom, Dec 29, 2004 IP
  3. jarvi

    jarvi Well-Known Member

    Messages:
    127
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    As mushroom says, use the str_replace to change the spaces to underscores, hyphens or something else.
     
    jarvi, Dec 29, 2004 IP
  4. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    64
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can't you just use urlencode?

    http://ca.php.net/manual/en/function.urlencode.php

    All spaces, as well as other special characters, will be replaced with proper hexadecimal sequences.

    J.D.
     
    J.D., Dec 30, 2004 IP
  5. hightide13

    hightide13 Peon

    Messages:
    127
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hey JD. I found the urlencode solution before I saw your response, but you are right. It worked like a charm! Thanks.
     
    hightide13, Dec 30, 2004 IP