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
https://forums.phpfreaks.com/topic/226143-passing-an-ampersand-in-a-url/
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.

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.