Page 1 of 1

Variable Problem in php

Posted: Thu Apr 26, 2007 5:40 am
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.

Posted: Thu Apr 26, 2007 6:24 am
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

Posted: Thu Apr 26, 2007 8:07 am
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']);

Posted: Thu Apr 26, 2007 8:15 am
by aaronhall
You're better off using urlencode() on outgoing GET values.. there are plenty of characters that should be encoded besides spaces.

Hi

Posted: Thu Apr 26, 2007 10:05 am
by dharprog
Hi

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

Thanks alot.