Jump to content

Passing an ampersand in a url


jeffkas

Recommended Posts

I am storing thousands of titles in mysql and many of these have a title with an ampersand. 

An example is how AT&T is getting stored in the database:  at-amp-t

 

Easy enough, I thought.. I'll just run str_replace on it before I save it to the database. 

$title = str_replace("-amp-", "&", $title);

 

That works great..  except when I click the new hyperlink created from this url.  It looks correct...  showing the exact url of what is stored in mysql:  (http://www.domain.com/this-is-the-at&t-title) ...but no url with this ampersand works.  All other $title urls works great.  If I don't run str_replace on it, it works fine.. but then I get a url stored as at-amp-t... which I'm trying to avoid. 

 

Thoughts? 

Link to comment
Share on other sites

Are you able to look in the HTML source of a page that links to the at&t url and see what it is doing?  You need to whatever it is doing.  Usually people don't use an "&" in the path component of a url, but if you wanted to do it I think you would encode it using urlencode().  htmlentities() is for displaying things in HTML, not for urls.

Link to comment
Share on other sites

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.