GridTrader Posted August 15, 2009 Share Posted August 15, 2009 Hi all. New here and pretty new to PHP. Very thankful to find this site. Will try to explain the best that I can. Thanks in advance anyone able to help In my template I have the following (bold area is what I am trying to address) <a href="<? echo $download_link; ?>" class="download_link"> I want the output of these urls to be encoded so that I can run another php script in front of them for tracking clicks: For example this $download_link puts out several random url's on a single page and one for example may look like this: http://www.mysite.com/fx/index.php?file=1&sort=1 Once I add my clicking tracking script to the url it looks like this: http://www.mysite.com/clicktrack/out.php?s=100&link=link1&url=http://www.mysite.com/fx/index.php?file=1&sort=1 I need an easy way to somehow encode the $download_link url so it will look like this: http%3A//www.mysite.com/fx/index.php%3Ffile%3D1%26sort%3D1 Otherwise the tracking script doesn't work right unless the urls in front of it are first encoded. Thank you, Jon Quote Link to comment https://forums.phpfreaks.com/topic/170373-solved-help-encoding-echo-download_link/ Share on other sites More sharing options...
oni-kun Posted August 15, 2009 Share Posted August 15, 2009 You can use PHP's urlencode(), But I believe the browser should already do that by default, nonetheless there it is. Quote Link to comment https://forums.phpfreaks.com/topic/170373-solved-help-encoding-echo-download_link/#findComment-898738 Share on other sites More sharing options...
GridTrader Posted August 15, 2009 Author Share Posted August 15, 2009 Thank you but how would I go about entering that to my line of code? I tried a few ways, but no luck. <a href="<? echo urlencode($download_link); ?>" class="download_link"> Sorry, I'm a PhpNewbie Quote Link to comment https://forums.phpfreaks.com/topic/170373-solved-help-encoding-echo-download_link/#findComment-898752 Share on other sites More sharing options...
oni-kun Posted August 15, 2009 Share Posted August 15, 2009 Try this. Some servers are mashy about shorthand tags.. <a href="<?php echo urlencode($download_link); ?>" class="download_link"> Urlencode should safely encode all HTML entities for you, that is what this feature is for. If you'd like to encode every possibly HTML entity then use htmlentities() on it instead.. but it shouldn't be needed for an url encoding. Edit: I get this, I tried it myself. http%3A%2F%2Fwww.mysite.com%2Ffx%2Findex.php%3Ffile%3D1%26sort%3D1 Quote Link to comment https://forums.phpfreaks.com/topic/170373-solved-help-encoding-echo-download_link/#findComment-898757 Share on other sites More sharing options...
GridTrader Posted August 15, 2009 Author Share Posted August 15, 2009 <a href="<?php echo urlencode($download_link); ?>" class="download_link"> This works, Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/170373-solved-help-encoding-echo-download_link/#findComment-898762 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.