doddsey_65 Posted May 4, 2011 Share Posted May 4, 2011 im using urlencode() to replace special characters in the url. It works on spacs, replacing them with '+' but it isnt working on a special character i have tried, the exclamation mark. Is this the right function to use for this? and if so why isnt it working for me? function create_url($str) { $str = urlencode($str); return $str; } function decode_url($str) { $str = urldecode($str); return $str; } i use the function create_url() for the link and use decode_url() when the link is clicked so i can display the proper name. eg: $forum_url_name = create_url($row['f_name']); and when viewing the forum: $forum_name = decode_url($_GET['f_name']); Quote Link to comment https://forums.phpfreaks.com/topic/235536-urlencode/ Share on other sites More sharing options...
silkfire Posted May 4, 2011 Share Posted May 4, 2011 Try to echo it out. Just tried urlencode and '!' became %21 so it definitely works. Quote Link to comment https://forums.phpfreaks.com/topic/235536-urlencode/#findComment-1210540 Share on other sites More sharing options...
btherl Posted May 5, 2011 Share Posted May 5, 2011 You typically do not need to urldecode a value from $_GET, because a single urldecoding pass is applied by PHP automatically. You would only need to urldecode it if it got double url encoded in the first place. As for why it's not working, I will need to see the full code, or a small sample code which demonstrates the problem. Quote Link to comment https://forums.phpfreaks.com/topic/235536-urlencode/#findComment-1210711 Share on other sites More sharing options...
doddsey_65 Posted May 5, 2011 Author Share Posted May 5, 2011 basically: the url reads like asimpleforum.co.uk/post/sample_post! so <a href="asimpleforum.co.uk/post/sample_post!"> htaccess is used so the actual url points to view_post.php?post_name=sample_post! that is how you access the post. When you click the link to view the post i run a query to get all of the post information but the query is run from the post name. so posts with a space are replaced with an underscore etc. The only problem is that using the ! in a url breaks it and sends a 404 error "page not found" so i tried using str_replace to replace the ! with %21. This threw the same 404 error. the same thing happened with urlencode. Quote Link to comment https://forums.phpfreaks.com/topic/235536-urlencode/#findComment-1210742 Share on other sites More sharing options...
Joshua F Posted May 5, 2011 Share Posted May 5, 2011 You might have to make the SQL Query load with %like%. Quote Link to comment https://forums.phpfreaks.com/topic/235536-urlencode/#findComment-1210744 Share on other sites More sharing options...
doddsey_65 Posted May 5, 2011 Author Share Posted May 5, 2011 that would run the risk of getting the wrong post. sample_post is like sample_post_1 Quote Link to comment https://forums.phpfreaks.com/topic/235536-urlencode/#findComment-1210745 Share on other sites More sharing options...
Joshua F Posted May 5, 2011 Share Posted May 5, 2011 that would run the risk of getting the wrong post. sample_post is like sample_post_1 That is true, I believe you have to allow % in the htaccess then. Quote Link to comment https://forums.phpfreaks.com/topic/235536-urlencode/#findComment-1210746 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.