dongshan2680 2017-11-02 09:17
浏览 74
已采纳

可以在file_get_content中设置php吗?

I would like to ask can i make the url in file_get_content() become changeable according to the port that user click? For example, if user click port2 will become

$html = file_get_contents('http://..port2.html');

while if user click port 3 will become

$html = file_get_contents('http://..port3.html');

i try to set the link as

$html = file_get_contents('http://..port<?=$mrtg_id?>.html');

but it shown error. Any suggestion?

  • 写回答

5条回答 默认 最新

  • duanmei1946 2017-11-02 09:20
    关注

    You can do it in more ways:

    $html = file_get_contents("http://..port".$mrtg_id.".html");
    $html = file_get_contents("http://..port{$mrtg_id}.html");
    $html = file_get_contents("http://..port{$mrtg_id}.html");
    $html = file_get_contents('http://..port'.$mrtg_id.'.html');
    

    Note the URL is enclosed with different characters (", ')

    Check the manual for more informations: http://php.net/manual/en/language.types.string.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?