Variable Problem in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Variable Problem in php

Post by dharprog »

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.
rebus
Forum Newbie
Posts: 11
Joined: Tue Nov 07, 2006 6:13 pm
Location: Croatia, Zadar

Post by rebus »

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
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

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']);
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

You're better off using urlencode() on outgoing GET values.. there are plenty of characters that should be encoded besides spaces.
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Hi

Post by dharprog »

Hi

Thats really working. Thank you very much guys for the Worthy help.

Thanks alot.
Post Reply