the_oliver Posted June 22, 2007 Share Posted June 22, 2007 Hello. I have a files which could be something like: gunk>stuff"yes.htm But when i link to them this causes havouc with the HTML! I tried relpacing them with \> and \" but that didn't make any diffrence. Whats the way round this? Thanks. Quote Link to comment Share on other sites More sharing options...
effigy Posted June 22, 2007 Share Posted June 22, 2007 url_encode. Quote Link to comment Share on other sites More sharing options...
the_oliver Posted June 22, 2007 Author Share Posted June 22, 2007 Hello, I tried all the options on that page and always got something like: e011_Again_It's_!_$_&_'_(_)_|_/%22_;_:_/_._%3C_%3E_`.htm in the link rather then the e011_Again_It's_!_$_&_'_(_)_|_\"_;_:_\_._<_>_`.htm i was expecting. (sory its so long! Just checking to see what causes problems!) They all replacesd the symbols with something else, rater then just telling it to do something like skip over them. Thanks. Quote Link to comment Share on other sites More sharing options...
effigy Posted June 22, 2007 Share Posted June 22, 2007 That's the point of urlencode. It turns any invalid characters (according to the specification) into hex values prefixed by a percent sign. Quote Link to comment Share on other sites More sharing options...
the_oliver Posted June 22, 2007 Author Share Posted June 22, 2007 Ok, but is there a way of doing the with out changing the charictors, as the file is named using the < > and " charictors not %3C etc. If i use %3C in the link, it tells me the page cannot be found! Thanks Quote Link to comment Share on other sites More sharing options...
effigy Posted June 22, 2007 Share Posted June 22, 2007 What does the code and source look like, and what is the actual file name? Quote Link to comment Share on other sites More sharing options...
the_oliver Posted June 22, 2007 Author Share Posted June 22, 2007 Actual file name: e011_Again_It's_!_$_&_'_(_)_|_\"_;_:_\_._<_>_`.htm Code: $htmlurl = "e011_Again_It's_!_$_&_'_(_)_|_\\\"_;_:_\_._<_>_`.htm"; $text .= "<a href=\"".urlencode($htmlurl)."\" target=\"blank\">$htmlurl</a>"; If i do View Source: <p>Your newsletter has been published as a web page.</p><p>It can be viewed online at: <a href="e011_Again_It%27s_%21_%26_%27_%28_%29_%7C_%22_%3B_%3A_%5C_._%3C_%3E_%60.htm" target="blank">e011_Again_It's_!_&_'_(_)_|_"_;_:_\_._<_>_`.htm</a> Quote Link to comment Share on other sites More sharing options...
effigy Posted June 22, 2007 Share Posted June 22, 2007 If you decode the output URL... <pre> <?php echo urldecode('e011_Again_It%27s_%21_%26_%27_%28_%29_%7C_%22_%3B_%3A_%5C_._%3C_%3E_%60.htm'); ?> </pre> ...you get... e011_Again_It's_!_&_'_(_)_|_"_;_:_\_._<_>_`.htm ...which isn't your file name. You're losing the dollar sign and the backslash before the double quote. Based on this, it looks like $htmlurl goes through some interpolation prior to being decoded. What does echo $htmlurl; show you? Quote Link to comment Share on other sites More sharing options...
the_oliver Posted June 22, 2007 Author Share Posted June 22, 2007 I think that must have been a typo. I ran: $htmlurl = "e011_Again_It's_!_$_&_'_(_)_|_\\\"_;_:_\_._<_>_`.htm"; $en = urlencode($htmlurl); echo $en."<br>"; //ENCODED echo $htmlurl."<br>"; //PLAIN echo urldecode($htmlurl); //DECODED And got e011_Again_It%27s_%21_%26_%27_%28_%29_%7C_%5C%22_%3B_%3A_%5C_._%3C_%3E_%60.htm e011_Again_It's_!_&_'_(_)_|_\"_;_:_\_._<_>_`.htm e011_Again_It's_!_&_'_(_)_|_\"_;_:_\_._<_>_`.htm Thanks for your help so far! Quote Link to comment Share on other sites More sharing options...
effigy Posted June 22, 2007 Share Posted June 22, 2007 The new encoding should work now... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.