php file_get_contents and &

后端 未结 7 2137
误落风尘
误落风尘 2020-12-07 00:48

I\'m trying to use php\'s file_get_content(\'a url\');

The thing is if the url has \'&\' in it, for example

file_get_contents(\'http://www.google.c

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 01:07

    The problem is most likely part of your PHP code. I suspect that what you think is happening is not actually happening.

    I suspect that rather than the code you posted, you are probably grabbing part of that URL from a variable, such as:

    $data = file_get_contents("http://example.com/?$myvariable");
    

    Echoing that variable to the browser may be hiding the fact that you've inadvertently encoded special characters in a previous step, because in the browser an "&" is going to look like "&".

    It's also possible that your file_get_contents() request is working correctly, and what you think is a problem with encoding the & sign may be a problem somewhere else - posting actual source code might help determining the problem.

提交回复
热议问题