graham23s Posted November 22, 2009 Share Posted November 22, 2009 Hi Guys, I have written a shopping cart that uses the Amazon API, a lot of amazon's products bring back some funky titles for example: The Major Works: including The Rape of the Lock and The Dunciad (Oxford World's Classics) i can't make this a hyperlink because of the ' and : symbols, is there somthing i can do to clean the titles before displaying them? thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/182502-dealing-with-in-url/ Share on other sites More sharing options...
cags Posted November 22, 2009 Share Posted November 22, 2009 Check out urlencode. Link to comment https://forums.phpfreaks.com/topic/182502-dealing-with-in-url/#findComment-963236 Share on other sites More sharing options...
graham23s Posted November 22, 2009 Author Share Posted November 22, 2009 Hi Cags, Thnaks mate, i did a test on the title above and the anchor text came out like: The+Major+Works%3A+including+The+Rape+of+the+Lock+and+The+Dunciad+%28Oxford+World%27s+Classics%29-0199537615.html'>The+Major+Works%3A+including+The+Rape+of+the+Lock+and+The+Dunciad+%28Oxford+World%27s+Classics%29 what i am trying to do is make that title a hyperlink to the products page, but because of all the symbols in the title text it cuts me off, simple titles like: The Last Pope work perfect but the majority of amazons titles have symbols in them. thanks mate Graham Link to comment https://forums.phpfreaks.com/topic/182502-dealing-with-in-url/#findComment-963237 Share on other sites More sharing options...
cags Posted November 22, 2009 Share Posted November 22, 2009 So whats your point? The text you just posted is the valid url for the text you gave in your previous post. The ampersand and the colon are not 'URL friendly' as they have their own special meaning in an URL. To send those characters via a URL you have to encode them. Which is what urlencode does. Link to comment https://forums.phpfreaks.com/topic/182502-dealing-with-in-url/#findComment-963240 Share on other sites More sharing options...
graham23s Posted November 22, 2009 Author Share Posted November 22, 2009 Hi Mate, i ended up doing: function amazon_strip_symbols($stringToClean) { $new_string = preg_replace("/[^a-zA-Z0-9\s]/", " ", $stringToClean); return $new_string; } which seems to strip the gunk from the titles pulled back from amazon THEN they are hyperlined to a url for example: www.site.com/title-with-symbol's-book.html <- this symbol (') was crashing the script. cheers mate Graham Link to comment https://forums.phpfreaks.com/topic/182502-dealing-with-in-url/#findComment-963252 Share on other sites More sharing options...
cags Posted November 22, 2009 Share Posted November 22, 2009 Well glad you sorted it. I should point out that there's also the urldecode function which performs the opposite. Amazon themselves are using some form of variant of it, as you'll see if you search for that title you listed, if you look at the keyword attribute in the URL you'll see that the semicolon is replaced by %3A and spaces are replaced by +'s. Link to comment https://forums.phpfreaks.com/topic/182502-dealing-with-in-url/#findComment-963257 Share on other sites More sharing options...
FaT3oYCG Posted November 22, 2009 Share Posted November 22, 2009 amazon are most probably using a rewrite rule, they probably made this custom so people dont scrape their site whihc is what is trying to be done here lol. Link to comment https://forums.phpfreaks.com/topic/182502-dealing-with-in-url/#findComment-963263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.