我一直试图用php preg_match解析这个网站的源代码http://www.nzz.ch/aktuell/zuerich/stadt_region/notrufdienst-am-handgelenk-1.18068637几天没有成功。阅读与卷曲和搜索的标题也很好。preg_match不匹配
在用preg_match搜索描述时出错了。 preg_match('/Description" content="(.*)">/i', $content, $description); $ogdescription = substr($description[0], 22, -1);
该搜索的结果是:
Ein Telefon nützt wenig, wenn es sich im Notfall nicht in greifbarer Nähe befindet. Das haben sich die Gründer der Firma Limmex gedacht und eine Armbanduhr auf den Markt gebracht, die per Knopfdruck zum Mobiltelefon wird." /><meta name="Publisher" content="Neue Zürcher Zeitung AG, Switzerland"><meta name="email" content="[email protected]"><meta name="copyright" content="Copyright &copy; 2013 Neue Zürcher Zeitung AG, Switzerland, http://www.nzz.ch/agb"><meta http-equiv="content-language" content="de"><meta http-equiv="expires" content="-1"><meta name="Author" content="Impressum Neue Zürcher Zeitung, Switzerland, http://www.nzz.ch/impressum"><meta name="distribution" content="global"><meta name="robots" content="index, follow, noarchive, noodp"><meta name="revisit-after" content="1 hour"><meta http-equiv="pragma" content="no-cache"><meta property="fb:app_id" content="138008459595436"><meta property="og:title" content="Zürcher Jungunternehmen: Notrufdienst am Handgelenk - Übersicht Nachrichten - NZZ.ch"><meta property="og:type" content="article"><meta property="og:url" content="http://www.nzz.ch/aktuell/zuerich/stadt_region/notrufdienst-am-handgelenk-1.18068637"><meta property="og:image" content="http://images.nzz.ch/app.php/eos/v2/image/view/145/-/lead/25b76387/1.18068643.1366564054.jpg"><meta property="og:site_name" content="Neue Zürcher Zeitung"><meta name="viewport" content="width=1390"><meta name="application-name" content="NZZ Online"><meta name="msapplication-tooltip" content="Start NZZ Online in Site Mode"><meta name="msapplication-starturl" content="http://www.nzz.ch"><meta name="msapplication-window" content="width=1024;height=760"><meta name="msapplication-navbutton-color" content="#000000"><meta name="msapplication-task" content="name=Nachrichten; action-uri=http://www.nzz.ch/nachrichten; icon-uri=http://www.nzz.ch/version-2.8.1/bundles/website/img/favicon.ico"><meta name="msapplication-task" content="name=Finanzen; action-uri=http://www.nzz.ch/finanzen; icon-uri=http://www.nzz.ch/version-2.8.1/bundles/website/img/favicon.ico"><meta name="msapplication-task" content="name=Magazin; action-uri=http://www.nzz.ch/magazin; icon-uri=http://www.nzz.ch/version-2.8.1/bundles/website/img/favicon.ico"><meta name="msapplication-task" content="name=Marktplätze; action-uri=http://www.nzz.ch/marktplaetze; icon-uri=http://www.nzz.ch/version-2.8.1/bundles/website/img/favicon.ico"><link href="http://www.nzz.ch/version-2.8.1/bundles/website/img/favicon.ico" rel="icon" type="image/x-icon"><link rel="shortcut icon" href="http://www.nzz.ch/version-2.8.1/bundles/website/img/favicon.ico"><link rel="apple-touch-icon" href="http://www.nzz.ch/version-2.8.1/bundles/website/img/apple-touch-icon-57x57.png"><link rel="apple-touch-icon" sizes="72x72" href="http://www.nzz.ch/version-2.8.1/bundles/website/img/apple-touch-icon-72x72.png"><link rel="apple-touch-icon" sizes="114x114" href="http://www.nzz.ch/version-2.8.1/bundles/website/img/apple-touch-icon-114x114.png"><link rel="publisher" href="https://plus.google.com/118094012157733055567"><link rel="stylesheet" type="text/css" media="screen, projection, handheld, print" href="/bundles/website/css/jquery.fancybox-1.3.4.css"><title>Zürcher Jungunternehmen: Notrufdienst am Handgelenk - Übersicht Nachrichten - NZZ.ch</title><link rel="canonical" href="http://www.nzz.ch/aktuell/zuerich/stadt_region/notrufdienst-am-handgelenk-1.18068637"><link rel="stylesheet" type="text/css" href="/version-2.8.1/css/6927630.css"><link rel="stylesheet" type="text/css" media="print" href="/version-2.8.1/css/5bd0678.css"><meta http-equiv="imagetoolbar" content="false"><link rel="search" href="/search" title="Suche Neue Zürcher Zeitung, Switzerland, http://www.nzz.ch/search"><link rel="author" href="/impressum" title="Impressum Neue Zürcher Zeitung, Switzerland, http://www.nzz.ch/impressum"><link rel="copyright" href="/agb" title="Copyright &copy; 2013 Neue Zürcher Zeitung AG, Switzerland, http://www.nzz.ch/agb"><!--[if lt IE 9]><script type="text/javascript" src="/version-2.8.1/bundles/website/js/html5shiv.js"></script><![endif]--><!-- Maxymiser script start --><!-- Maxymiser script end -->
我做了什么错,这需要所有的源代码?
下一个问题:
preg_match('/escription" content="(.*?)" \/>/i', $content, $description);
$ ogdescription = $描述[1];
<meta name="twitter:description" content="Am 17 .4. 2013 beschäftigte sich das Ö1-Gesundheitsmagazin mit Persönlicher Assistenz und dem Recht auf Selbstbestimmung.">
为什么不匹配它?
它是更好地使用DOM文档对于这个 – 2013-04-22 08:19:29