file_get_html奇怪的输出 [英] file_get_html weird output

查看:74
本文介绍了file_get_html奇怪的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了非常小的代码,如下所示.

I've written a very small piece of code as you can see below.

<?php
include_once 'simple_html_dom.php';

$url = "http://passenger.cm.be/nl/contactpoints/723?service-1057";

$html = file_get_html($url);

echo $html;
?>

当我在wamp家庭服务器上运行此代码时,它将按原样显示该网页. 但是,当我将其上传到在线服务器时,会得到以下结果:

When I run this code on my wamp homeserver, it is showing the webpage as it should. However, when I upload it to my online server I'm getting the result below:

{"contactpoint_address_id":723,"hq":null,"id":723,"language":2,"name":"CM-kantoor Aalst","zf":12,"address":{"bus":null,"contactpoint_municipality_id":631,"id":723,"lat":50.93767,"lng":4.037621,"municipality_name_de":"AALST","municipality_name_fr":"AALST","municipality_name_nl":"AALST","number":"10","street":"HOPMARKT","street_de":"HOPMARKT","street_fr":"HOPMARKT","street_nl":"HOPMARKT","zip":9300,"town":{"cm_id":1,"description_nl":"AALST","description_fr":"AALST","description_de":"AALST","id":9300,"nis":9300,"zip":9300}},"region":{"cm_region_id":120,"description_de":"CM Midden-Vlaanderen","description_fr":"CM Midden-Vlaanderen","description_nl":"CM Midden-Vlaanderen","id":12},"contactpoint_services":[{"contactpoint_id":723,"id":1057,"remark_closingdays":null,"remark_general":null,"remark_id":null,"remark_openinghours":"De CM-consulenten werken ook op afspraak. Een afspraak maken kan op de afsprakenwebsite of op 09 224 77 22.","service_id":1,"service":{"available_in_de":1,"available_in_fr":1,"available_in_nl":1,"description_de":"Gesch\u00e4ftsstelle","description_fr":"Agence","description_nl":"kantoor","icon":null,"id":1},"contactinfos":[{"contactinfo_type_id":2,"contactpoint_service_id":1057,"display_order":1,"id":379,"info":"053 76 15 16"},{"contactinfo_type_id":3,"contactpoint_service_id":1057,"display_order":1,"id":633,"info":"aalst.mvl@cm.be"},{"contactinfo_type_id":1,"contactpoint_service_id":1057,"display_order":1,"id":259,"info":"09 224 77 22"}],"hourinfo":{"contactpoint_service_id":1057,"id":2252,"remark_de":null,"remark_fr":null,"remark_nl":null},"openinghours":[{"contactpoint_service_id":1057,"day":1,"from":"09:30","id":2248,"sort_order":1,"until":"12:00","day_name":"Maandag"},{"contactpoint_service_id":1057,"day":1,"from":"13:30","id":2249,"sort_order":2,"until":"16:00","day_name":"Maandag"},{"contactpoint_service_id":1057,"day":2,"from":"09:30","id":2250,"sort_order":1,"until":"12:00","day_name":"Dinsdag"},{"contactpoint_service_id":1057,"day":3,"from":"09:30","id":2251,"sort_order":1,"until":"12:00","day_name":"Woensdag"},{"contactpoint_service_id":1057,"day":3,"from":"13:30","id":2252,"sort_order":2,"until":"16:00","day_name":"Woensdag"},{"contactpoint_service_id":1057,"day":4,"from":"09:30","id":2253,"sort_order":1,"until":"12:00","day_name":"Donderdag"},{"contactpoint_service_id":1057,"day":4,"from":"13:30","id":8451,"sort_order":2,"until":"16:00","day_name":"Donderdag"},{"contactpoint_service_id":1057,"day":5,"from":"09:30","id":2254,"sort_order":1,"until":"12:00","day_name":"Vrijdag"}]},{"contactpoint_id":723,"id":906,"remark_closingdays":null,"remark_general":null,"remark_id":null,"remark_openinghours":null,"service_id":2,"service":{"available_in_de":1,"available_in_fr":1,"available_in_nl":1,"description_de":"Briefkasten","description_fr":"Bo\u00eete aux lettres ou correspondant mutualiste","description_nl":"brievenbus","icon":null,"id":2},"contactinfos":[],"openinghours":[]},{"contactpoint_id":723,"id":4252,"remark_closingdays":null,"remark_general":"De adviserend geneesheer werkt op afspraak.","remark_id":null,"remark_openinghours":null,"service_id":4,"service":{"available_in_de":0,"available_in_fr":0,"available_in_nl":1,"description_de":"Vertrauensarzt","description_fr":null,"description_nl":"adviserend geneesheer","icon":null,"id":4},"contactinfos":[],"openinghours":[]},{"contactpoint_id":723,"id":1330,"remark_closingdays":null,"remark_general":"Je maakt een afspraak wanneer het jou past.\nAls je dat verkiest, komen we aan huis.\n\nTelefonisch bereikbaar op 09 267 59 09\nvan 8.30 tot 12.00 en van 13.00 tot 17.00 uur.\nOp dinsdag tot 12.00 en vrijdag tot 16.00 uur.\nE-mail: mwzorg.mvl@cm.be\n\nJe kunt ook langskomen tijdens de openingsuren.","remark_id":null,"remark_openinghours":null,"service_id":6,"service":{"available_in_de":1,"available_in_fr":1,"available_in_nl":1,"description_de":"Sozialdienst","description_fr":"Service social","description_nl":"dienst Maatschappelijk Werk","icon":null,"id":6},"contactinfos":[{"contactinfo_type_id":1,"contactpoint_service_id":1330,"display_order":1,"id":2196,"info":"09 267 59 09"}],"hourinfo":{"contactpoint_service_id":1330,"id":7182,"remark_de":null,"remark_fr":null,"remark_nl":null},"openinghours":[{"contactpoint_service_id":1330,"day":1,"from":"13:00","id":7182,"sort_order":1,"until":"17:00","day_name":"Maandag"}]},{"contactpoint_id":723,"id":3992,"remark_closingdays":null,"remark_general":"De Thuiszorgcentra zijn telefonisch bereikbaar via de Zorgtelefoon op 078 152 152. Je kunt mailen naar thuiszorgcentrum.mvl@cm.be","remark_id":null,"remark_openinghours":null,"service_id":7,"service":{"available_in_de":0,"available_in_fr":0,"available_in_nl":1,"description_de":null,"description_fr":null,"description_nl":"Thuiszorgcentrum","icon":null,"id":7},"contactinfos":[{"contactinfo_type_id":1,"contactpoint_service_id":3992,"display_order":1,"id":2197,"info":"078 152 152"}],"openinghours":[]}]}

我绝对不知道这是什么,为什么会这样显示. 有没有其他人以前遇到过这个问题,并且知道解决方法?

I have absolutely no idea what this is and why it is showing like this. Has anyone else experienced this problem before and know a solution?

谢谢.

推荐答案

使用cURL代替下载网页...

Use cURL instead to download the web page...

这是我用于此目的的功能:

Here's a function I use for that purpose:

function dlPage($href) {

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_URL, $href);
    curl_setopt($curl, CURLOPT_REFERER, $href);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    $str = curl_exec($curl);
    curl_close($curl);

    return $str;
}

然后您以这种方式加载内容:

Then you load the content this way:

$url = "http://passenger.cm.be/nl/contactpoints/723?service-1057";

// Create a DOM object & load HTML from a URL 
$html = new simple_html_dom();

// Load HTML from a string
$html->load(dlPage($url));

echo $html;

并确保您已激活php cURL模块...

And be sure you have the php cURL module activated...

这篇关于file_get_html奇怪的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆