jaymc Posted August 16, 2007 Share Posted August 16, 2007 Is there any reason why urldecode("JMC%20&%20U.K%20Soulja"); returns "JMC " Please advise I cant seem to get this working! Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/ Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 return JMC & U.K Soulja Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325917 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 you should use urlencode("JMC & U.K Soulja"); as the & will confuse the URL urlencode("JMC & U.K Soulja"); returns JMC+%26+U.K+Soulja which is safe to pass via the URL Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325919 Share on other sites More sharing options...
jaymc Posted August 16, 2007 Author Share Posted August 16, 2007 Yeh but when JMC+%26+U.K+Soulja is past to a page I need to change it back into JMC & U.K Soulja for use with mysql insertion Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325920 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 basic example <?php $data = "JMC & U.K Soulja"; echo urldecode($_GET['NewData']); ?> <a href="?NewData=<?php echo urlencode($data);?>">test</a> try this on a new php file. Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325923 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 Try rawurldecode(). Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325925 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 Note: rawurldecode() does not decode plus symbols ('+') into spaces. urldecode() does. Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325927 Share on other sites More sharing options...
jaymc Posted August 16, 2007 Author Share Posted August 16, 2007 basic example <?php $data = "JMC & U.K Soulja"; echo urldecode($_GET['NewData']); ?> <a href="?NewData=<?php echo urlencode($data);?>">test</a> try this on a new php file. Yes thats working fine, but that not the problem The problem is I am using $_GET to retrieve info from that URL, however when its been decoded the name is not coming out as JMC & U.K Soulja its coming out as it is decoded So, I need a way to convert a decoded URL into an UNECODED one Before = JMC+%26+U.K+Soulja After = JMC & U.K Soulja Ive also tried rawurldecode Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325928 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 Oh, it is because the $_GET array is only holding JMC. When you pass a value by GET like that, it delimits by whitespaces so your php file is only receiving up to the first space. I think you are going to have to correct the way it sends the data. Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325931 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 really you should fix the sending process but heres an idea.. <?php echo "test2<br /><br />"; $data = "JMC & U.K Soulja"; $test = urldecode($_SERVER['QUERY_STRING']); if (preg_match('/=(.*)/i', $test, $regs)) { $result = $regs[1]; } echo $result; ?> <a href="?newdata=<?php echo $data;?>">test</a> Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325935 Share on other sites More sharing options...
jaymc Posted August 16, 2007 Author Share Posted August 16, 2007 Oh, it is because the $_GET array is only holding JMC. When you pass a value by GET like that, it delimits by whitespaces so your php file is only receiving up to the first space. I think you are going to have to correct the way it sends the data. Thats not the case I used rawurlencode to make the URL safe, then strangely enough just echoing the $_GET works I think php is decoding it for me automatically.. Anyway, solved. Thanks for input guys Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325940 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 please click topic solved Link to comment https://forums.phpfreaks.com/topic/65268-solved-urldecode/#findComment-325942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.