Jump to content

[SOLVED] Help encoding echo $download_link


GridTrader

Recommended Posts

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 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/170373-solved-help-encoding-echo-download_link/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.