...

View Full Version : Space in the middle of a PHP Link



tmarch291
05-17-2011, 03:22 AM
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:

$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:


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

Fou-Lu
05-17-2011, 03:35 AM
I'll use a printf since I much prefer:


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.


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

tmarch291
05-17-2011, 04:26 AM
Thank you very much!

It is working fine now.

SKY-ProToSs
05-17-2011, 04:45 AM
I'll use a printf since I much prefer:


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.


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum