请教php解析url的内容
程序员文章站
2022-04-07 18:36:58
...
请教各位,我有一个URL : http://help.ea.com/en/server-status/fifa-2016/
请教我如何把内容里 PC Game Servers ,Playstation 3 ,XBOX 360,XBOX One,Playstation 4这些属性下的UPDATED解析到?然后用PHP页面显示出来?
能否给段完整的代码?我刚学PHP, 获取HTML内容没搞定我
能否给段完整的代码?我刚学PHP, 获取HTML内容没搞定我
$html= file_get_contents($url);
请教我如何把内容里 PC Game Servers ,Playstation 3 ,XBOX 360,XBOX One,Playstation 4这些属性下的UPDATED解析到?然后用PHP页面显示出来?
回复讨论(解决方案)
//$html 就是获取的页面 html$s = simplexml_load_string($html);foreach($s->ul[0] as $li){ echo $li->h6[0].' - '.$li->p[0].'
';}/*PC Game Servers - Updated: 9:51 PM CST May, 15 Playstation 3 - Updated: 9:51 PM CST May, 15 XBOX 360 - Updated: 9:51 PM CST May, 15 XBOX One - Updated: 9:51 PM CST May, 15 Playstation 4 - Updated: 9:51 PM CST May, 15 */
//$html 就是获取的页面 html$s = simplexml_load_string($html);foreach($s->ul[0] as $li){ echo $li->h6[0].' - '.$li->p[0].'
';}/*PC Game Servers - Updated: 9:51 PM CST May, 15 Playstation 3 - Updated: 9:51 PM CST May, 15 XBOX 360 - Updated: 9:51 PM CST May, 15 XBOX One - Updated: 9:51 PM CST May, 15 Playstation 4 - Updated: 9:51 PM CST May, 15 */
能否给段完整的代码?我刚学PHP, 获取HTML内容没搞定我
//$html 就是获取的页面 html$s = simplexml_load_string($html);foreach($s->ul[0] as $li){ echo $li->h6[0].' - '.$li->p[0].'
';}/*PC Game Servers - Updated: 9:51 PM CST May, 15 Playstation 3 - Updated: 9:51 PM CST May, 15 XBOX 360 - Updated: 9:51 PM CST May, 15 XBOX One - Updated: 9:51 PM CST May, 15 Playstation 4 - Updated: 9:51 PM CST May, 15 */
能否给段完整的代码?我刚学PHP, 获取HTML内容没搞定我
$html= file_get_contents($url);
网站做了限制,你要打开这个网页查看它的cookie,并复制出来放在 $strCookie 中,我的cookie串就是下面 $strCookie的内容,改成你的就可以了
$strCookie = 'oauth_redirect=/en/server-status/fifa-2016/; PHPSESSID=nuqjjqj9aagnc8j2mglf82dj45; AWSELB=A32F41DF08C4BE7B7084C2525E0A6EA0DB38F970292F10DAB9FBCCA7735A84837B2C3A00FA5C83230EF9357A7A9E719B7CF0224072C74548F89DB34FEF6BDDBD0F640DAA52E77AC24ADCBD1AEEB365AA2D9CA5CA37';$url = 'http://help.ea.com/en/server-status/fifa-2016/';$html = mcurl($url,$strCookie); //紧接上面的代码//$s = simplexml_load_string($html);.....function mcurl($url,$strCookie) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_COOKIE, $strCookie); $data = curl_exec($ch); curl_close($ch); return $data;}
上一篇: php性能优化实例分享