Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Space in the middle of a PHP Link

    Hi all,

    I'm a PHP novice (I'd like to think I'm a step up from a noob) and I am having an odd problem with a link in a website I'm creating for an animal taxonomy project.

    Here is an example of the problem:

    Let's say I want to look up a domestic cat (Felis catus.)

    So:
    Code:
    $Species="Felis Catus";
    Now, the site I am building will link to a page showing a detailed description of this animal. To do this I use:

    Code:
    Print "<th><a href=species_info.php?Species=$Species>$Species</a>". "</th>";
    The only problem is, that it only forwards the word "Felis" to the next page. In other words, it throws out everything on the other side of the space.

    I tried researching the problem, however, I havent found much. If any of you could offer any insight, it would be much appreciated.

    Thanks,
    Tim

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I'll use a printf since I much prefer:
    PHP Code:
    printf('<th><a href="species_info.php?Species=%s">%s</a></th>'urlencode($Species), $Species); 
    All you need is the urlencode to convert the ' ' to %20.

    Edit:
    Sorry, the ' ' will become +. Thats fine, browsers understand either as a space.

  • Users who have thanked Fou-Lu for this post:

    tmarch291 (05-17-2011)

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you very much!

    It is working fine now.

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    111
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    I'll use a printf since I much prefer:
    PHP Code:
    printf('<th><a href="species_info.php?Species=%s">%s</a></th>'urlencode($Species), $Species); 
    All you need is the urlencode to convert the ' ' to %20.

    Edit:
    Sorry, the ' ' will become +. Thats fine, browsers understand either as a space.
    That's good to know if I ever decide to use a string in my url :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •