Hi
How are you all?
I'm getting a problem that is like this.
I'm passing a variable from one page to another page suppose the link is like this
http://clickflick.com/index.php?cat=Family
Here cat variable does have only single word "Family" for this i'm not getting problem when it comes to like
http://clickflick.com/index.php?cat=Holocaust Drama in this cat variable does have the word of "Holocaust Drama"
the problem here is its not taking the whole , its just breaking up and taking the variable as Holocaust (That broken variable link is http://clickflick.com/index.php?cat=Holocaust ).
How can i solve this problem without breaking up that word when we pass in this how can i resolve in this in php?
Please help me out
Thank You very much.
Variable Problem in php
Moderator: General Moderators
Try this:
http://clickflick.com/index.php?cat=Holocaust%20Drama
Notice %20 which stands for whitespace.
You can use url_encode function to encode white spaces and stuff your gona pass throu GET.
http://php.net/url_encode
http://clickflick.com/index.php?cat=Holocaust%20Drama
Notice %20 which stands for whitespace.
You can use url_encode function to encode white spaces and stuff your gona pass throu GET.
http://php.net/url_encode
or use the str_replace function
Code: Select all
echo "<a href='somepage.php?cat=".str_replace(" ","_","Holocaust Drama")."'>Holocaust Drama</a>";
//and on the other page you reverse the str_replace
$str = str_replace("_"," ",$_GET['cat']);- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
You're better off using urlencode() on outgoing GET values.. there are plenty of characters that should be encoded besides spaces.