ginerjm Posted February 2, 2023 Share Posted February 2, 2023 I have never had to deal with this so I'm a bit lost. I have a php script that needs to send an anchor tag that looks like: members_by_age_rpt.php?range=25%20&%20Under With PHP the problem is I don't know what I have to do to the 'range' value to make it recognizable. Tried html_entity_decode but that doesn't seem to be the proper treatment. So what is it I have to do to end up with a proper 'range' value/string of "25 & Under"? Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/ Share on other sites More sharing options...
Solution kicken Posted February 2, 2023 Solution Share Posted February 2, 2023 urlencode or http_build_query. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605290 Share on other sites More sharing options...
ginerjm Posted February 2, 2023 Author Share Posted February 2, 2023 Don't know why the site created a second topic of this item. There is some kind of change that asks one to supply an answer to recognize solutions that I never saw before. Must me that. And for all I know there may be another. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605291 Share on other sites More sharing options...
ginerjm Posted February 2, 2023 Author Share Posted February 2, 2023 OK - this is what I attempted. $url_qry = urlencode($c); echo "c is $c and url_qry is now $url_qry<br>"; Then I output my html with echo "<a href='members_by_age_rpt.php?range=$url_qry'>$c</a>"; but what does my receiving script have to do to interpret that range value now? http://xxx.com/tools/members_by_age_rpt.php?range=25+%26+Under This is what comes in. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605292 Share on other sites More sharing options...
ginerjm Posted February 2, 2023 Author Share Posted February 2, 2023 Never mind - Discovered the function "urldecode". Thanks to Kicken. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605294 Share on other sites More sharing options...
kicken Posted February 2, 2023 Share Posted February 2, 2023 You shouldn't have to decode the value, PHP does that automatically when it parses the query string and builds the $_GET array. If you're having to decode it, then you're encoding it unnecessarily. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605297 Share on other sites More sharing options...
ginerjm Posted February 2, 2023 Author Share Posted February 2, 2023 As you can see my incoming url had the + chars in it and I had to dump them. They were a direct result of doing the encode. Prior to that I had ampersanded numbers (chars) in the query value. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605298 Share on other sites More sharing options...
requinix Posted February 2, 2023 Share Posted February 2, 2023 Then rawurlencode was the more appropriate one, however http_build_query is nicer so use that. <a href="http://xxx.com/tools/members_by_age_rpt.php?<?= http_build_query(["range" => $variable]) ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605323 Share on other sites More sharing options...
ginerjm Posted February 2, 2023 Author Share Posted February 2, 2023 But as I've discovered the original tip to use urlencode and then the decode version solved my problem. And so Quickly! Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605330 Share on other sites More sharing options...
requinix Posted February 2, 2023 Share Posted February 2, 2023 If you have to urldecode a query parameter yourself then you are doing something wrong. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605332 Share on other sites More sharing options...
ginerjm Posted February 2, 2023 Author Share Posted February 2, 2023 Then I must have done something wrong when I used urlencode as well? Never had to do anything like this before cause I never had a parms with an & in them before. It's quite possible I did something wrong but it all ended up just fine. Quote Link to comment https://forums.phpfreaks.com/topic/315869-query-parms-with-in-them/#findComment-1605333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.