想要从PHP中复制其他网站的特定文本

时间:2016-12-26 14:44:38

标签: php

Ltes说我想复制网站上的文字(http:// www.example.com/ex)

当我打开http:/ /www.example.com/ex时,会显示此数据click here

我想复制MrsId之后的每个文本,它位于双引号之间(意味着我想复制MN4D / CN4D / MK4D / MO4D以及所有来自example.com/ex的四个代码,这些代码每天都会更改)

和sotre in varible eg($ a ='MN4D',$ b ='CN4D',$ c ='MK4D',$ d ='MO4D')

然后想用它作为

$ first ='http:// www.example.com/?code=';
 $ url =“{$ first} {$ a}”;
 $ urll =“{$ firsts} {$ b}”;
 $ urlll =“{$ firsts} {$ c}”;
 $ urlllll =“{$ firsts} {$ d}”;

$ result = file_get_contents($ url);
$ results = file_get_contents($ urll);
$ resultss = file_get_contents($ urlll);
$ resultsss = file_get_contents($ urllll);

echo $ result;
echo $ results;
echo $ resultss;
echo $ resultsss;


我从1个月开始研究这段代码,但还没有成功。

2 个答案:

答案 0 :(得分:0)

我可以看到 - 数据有json格式。因此,您可以使用json_decode访问所需的字段

答案 1 :(得分:0)

根据需要更改代码:

<?php
$json = '{"Amrlist":[{"Amcd":"mr-pub-4925511/1986","MrsId":"MN4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"},{"Amcd":"mr-pub-4925511/1986","MrsId":"CN4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"},{"Amcd":"mr-pub-4925511/1986","MrsId":"MK4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"},{"Amcd":"mr-pub-4925511/1986","MrsId":"MO4D","BiclMine":"90","ImagePath":"http://my.example.com/myex/myex.jpg"}]}';

$decoded = json_decode($json, true);
//var_dump($decoded);
$url = 'http://www.example.com/?code=';
foreach($decoded{'Amrlist'} as $Amrlist) {
  //print_r($Amrlist);
  print $url.$Amrlist['MrsId']."\n";
  //print file_get_contents($url.$Amrlist['MrsId']);
}
/**/
?>