我在页面上有一个文本,我想通过使用获取到其他页面
preg_match
和file_get_content
函数
page1.php
上的文字是
return(["h","t","t","p",":","\/","\/","1","7",".","2","4","8",".","1","7","4",".","3","8",":","8","0","8","1","\/"])
我想从page1.php
到page2.php
这样的文字
IP是:http://17.248.174.38:8081/
IP现在自动为17.248.174.38:8081,刷新后可以变为133.213.171.33:8081所以它是从page1生成的
我试过这段代码,但它不能正常工作
<?php
$url = "http://localhost/page1.php";
$contents = file_get_contents($url);
preg_match('/(http?\:\/\/[^\']*\.8081*)/', $contents, $result);
$link = urldecode($result[0]);
$echo "The IP is :" $link;
?>
任何帮助请,我只是php的初学者
IP 17.248.174.38可以在刷新页面时随时更改
感谢
答案 0 :(得分:0)
已更新
page2.php中的使用此
<?php
$url = "page1.php"; // use file location in refrence of the current file.
$contents = file_get_contents($url);
preg_match('/return\(\[\"h\",\"t\",.+\]\)/i', $contents, $result);
$result = json_decode(trim(str_replace("return","",$result[0]),"()"));
$link = urldecode($result);
$echo "The IP is :" $link;
?>
json_decode()
用于解码和解析响应(这是一个JSON数组),然后implode()
将所有数组元素连接成一个字符串,因此可以将其传递给{{1} }。
希望这会有所帮助:)