ciber Posted December 13, 2009 Share Posted December 13, 2009 I am wanting to convert a URL to a specific format, what PHP function would I use. This is what the URL looks like : http://www.amazon.com/ This is what I need it to be converted to: http%3A%2F%2Fwww.amazon.com%2F Since it is used like this :: http://www.amazon.com/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.com%2F Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/ Share on other sites More sharing options...
Buddski Posted December 13, 2009 Share Posted December 13, 2009 I dont know if there is a specific function for this but my best guess would be to do something like this.. <?php $input = 'http://www.amazon.com/'; for ($i=0;$i<strlen($input);$i++) { echo dechex(ord($input{$i})); } ?> Then filter out the chars you dont want to change.. Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/#findComment-976416 Share on other sites More sharing options...
AE117 Posted December 13, 2009 Share Posted December 13, 2009 It looks like you are replacing all the / with % $http = "THE Url You want to rewrite"; $rewrite_http = str_replace("/", "%", "$http"); echo $rewrite; Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/#findComment-976419 Share on other sites More sharing options...
ciber Posted December 13, 2009 Author Share Posted December 13, 2009 It looks like you are replacing all the / with % $http = "THE Url You want to rewrite"; $rewrite_http = str_replace("/", "%", "$http"); echo $rewrite; ?? dude look closer, i ain't just changing the the / to %, if you notice '%2F' is the hex representation of '/' Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/#findComment-976429 Share on other sites More sharing options...
ciber Posted December 13, 2009 Author Share Posted December 13, 2009 sigh ... nevermind, function I was supposed to use was right, stupid me made a typo .. no wonder it was not working Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/#findComment-976433 Share on other sites More sharing options...
emopoops Posted December 13, 2009 Share Posted December 13, 2009 WHY DO U NEED TO do that? why does it need to be converted? i have a get variable that contains a url i use for redirecting and it works just fine no converts needed Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/#findComment-976500 Share on other sites More sharing options...
salathe Posted December 13, 2009 Share Posted December 13, 2009 It hasn't been mentioned in this thread yet, but a function to do this is urlencode. Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/#findComment-976501 Share on other sites More sharing options...
emopoops Posted December 13, 2009 Share Posted December 13, 2009 yeah i was thinking of the urlencode thing before i posted i just couldnt remember the name. i had to use it in a feed on a php page to encode the url that had like get variables in it and spaces whatnot.. to validate the feed. Link to comment https://forums.phpfreaks.com/topic/184964-converting-a-url-to-hex/#findComment-976504 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.