-
Spaces in String?
Can I put spaces in strings? If so do I need to do anything special? Here's the deal, I'm doing something to make my life easier, I'm making all contact links fill in the subject on my form script automatically, here's and example of what I'm doing:
<a href="contact.php?why=Submit&what=News&which=ConcertDates">Submit Concert Dates</a>
Now I was just wondering if and how to put spaces in the string so it would be like this:
<a href="contact.php?why=Submit&what=News&which=Concert Dates">Submit Concert Dates</a>
Can I do that or should I just make extra fields like which1 which2 etc..?
-
Probably best to do something like this Concert_Dates
the $info = str_replace ("_", " ", $String);
That will give you back your spaces.;)
-
using str_repalce(" ", "_", $str) is th wrong approach sine you will need to pull the underscores off in the processing, it would be much better to use urlencode to fill the spaces with + signs, that way you have to do nothing on the following pages to get the variables to look like they started. For instance
<a href="contact.php?why=Submit&what=News&which=Concert+Dates">Submit Concert Dates</a>
On the next page $which would look like "Concert Dates". To do this simplky manually put them in therre or run $var = urlencode($var); before using the var in a link.
-
By default you should use plus signs instead of spaces. Use url_encode() to do this
Sean :)
Edit:
freddy beat me! :D
-
And its urlencode() not url_encode() ;)
-
I thought it had the underscore, in fact I have got a book that includes it! I'll have to buy the ultimate guide to PHP by freddydoesphp, can't argue with a name like that :D
Sean :)
-
-
Apart from this the book is great, I did check the manual after you posted. So what do you think take my pen to my book or ask Zend to change the function name? :p
Sean :)
-
-
%20 is what you would get by running rawurlencode() and would work the same way.
-
can't you use a space itself in the link? i thought the browser would convert it to a "+" just as when you submit a GET (or POST) form. and then PHP takes care converting to the real characters like a space doesn't it?
EDIT: i just tried it with regular spaces, and it's that way when it comes into the PHP script.