Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.