carlwenrich Posted April 14, 2008 Share Posted April 14, 2008 I'd like to use file_get_contents to read a url, but when the url contains an ampersand (for the second passed arg) everything after the ampersand (including the ampersand itself) is ignored. Link to comment https://forums.phpfreaks.com/topic/100992-how-do-i-escape-an-ampersand-in-a-url/ Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 & You can do this automatically by using htmlentities() Link to comment https://forums.phpfreaks.com/topic/100992-how-do-i-escape-an-ampersand-in-a-url/#findComment-516478 Share on other sites More sharing options...
carlwenrich Posted April 14, 2008 Author Share Posted April 14, 2008 Actually, I don't think so. I think that's for a different situation. Here's the code: $url = "http://finance.yahoo.com/q/op?s=BJS&m=2008-05"; $content = file_get_contents($url); The page that gets returned is the one for this url: http://finance.yahoo.com/q/op?s=BJS which is the first month of options, whereas I need the second one. Link to comment https://forums.phpfreaks.com/topic/100992-how-do-i-escape-an-ampersand-in-a-url/#findComment-516782 Share on other sites More sharing options...
GingerRobot Posted April 14, 2008 Share Posted April 14, 2008 It appears to work fine for me. In any case, you shouldn't have need to escape the ampersand - it is being used to separate the arguments. What version of PHP are you using? Link to comment https://forums.phpfreaks.com/topic/100992-how-do-i-escape-an-ampersand-in-a-url/#findComment-516788 Share on other sites More sharing options...
laffin Posted April 14, 2008 Share Posted April 14, 2008 I think thats his point. it's not taking the 2nd parameter. for me it worked fine using php5 and php4. <?php $url = "http://finance.yahoo.com/q/op?s=BJS&m=2008-05"; echo file_get_contents($url); ?> so sumfin else is going on with yer setup, or the coding u use to generate the url Link to comment https://forums.phpfreaks.com/topic/100992-how-do-i-escape-an-ampersand-in-a-url/#findComment-517102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.