Regular Expression to get contents of div class in php

Possible Duplicate: PHP DOMDocument, finding specific tags How to parse and process HTML with PHP? Is there any special syntax to get nested div element with unique class name in RegExp in php. Consider I have a syntax like <div style="demo"> <div class="row"> <div title="abc@examples.com" class="text">ABC</div> </div> <div class="row"> <div

正则表达式在php中获取div类的内容

可能重复: PHP DOMDocument,找到特定的标签 如何使用PHP解析和处理HTML? 有没有什么特殊的语法来获取嵌套div元素与唯一的类名在RegExp在PHP中。 考虑我有一个类似的语法 <div style="demo"> <div class="row"> <div title="abc@examples.com" class="text">ABC</div> </div> <div class="row"> <div title="pqr@examples.com" class="text">PQR</div> </d

Extracting XML data to php

This question already has an answer here: How do you parse and process HTML/XML in PHP? 28 answers $string_data = "<your xml response>"; $xml = simplexml_load_string($string_data); $latitude = (string) $xml->Latitude; $longitude = (string) $xml->Longitude; echo $latitude.' '.$longitude; 很简单,使用PHP的SimpleXML库: $xml = simplexml_load_file("http://freegeoip.net/xml/google.com"

将XML数据提取到php

这个问题在这里已经有了答案: 如何解析和处理PHP中的HTML / XML? 28个答案 $string_data = "<your xml response>"; $xml = simplexml_load_string($string_data); $latitude = (string) $xml->Latitude; $longitude = (string) $xml->Longitude; echo $latitude.' '.$longitude; 很简单,使用PHP的SimpleXML库: $xml = simplexml_load_file("http://freegeoip.net/xml/google.com"); echo $xml->Ip; // 173

Get contents of a div from a URL

Possible Duplicate: How to implement a web scraper in PHP? How to parse and process HTML with PHP? I need to crawl through a page and get the contents of a particular div. I have php and javascript as my two main options. How can it be done? This is quite a basic method to do it PHP and it returns the content in plain text. However you might consider revising the regex for your particu

从URL获取div的内容

可能重复: 如何在PHP中实现一个Web刮板? 如何使用PHP解析和处理HTML? 我需要抓取一个页面并获取特定div的内容。 我有两个主要选项的PHP和JavaScript。 如何做呢? 这是完成PHP的基本方法,它以纯文本形式返回内容。 不过,您可能会考虑修改正则表达式以满足您的特定需求。 <?php $link = file_get_contents("http://www.domain.com"); $file = strip_tags($link, "<div>"); preg_match_all("/<d

PHP parse HTML tags

Possible Duplicate: How to parse and process HTML with PHP? I'm pretty new to PHP. I have the text of a body tag of some page in a string variable. I'd like to know if it contains some tag ... where the tag name tag1 is given, and if so, take only that tag from the string. How can I do that simply in PHP? Thanks!! You would be looking at something like this: <?php $content

PHP解析HTML标签

可能重复: 如何使用PHP解析和处理HTML? 我对PHP很新。 我有一个字符串变量中某个页面的body标签的文本。 我想知道它是否包含一些标签...在哪里给出标签名称tag1,如果是,则只从该字符串获取该标签。 我怎么能在PHP中简单地做到这一点? 谢谢!! 你会看到像这样的东西: <?php $content = ""; $doc = new DOMDocument(); $doc->load("example.html"); $items = $doc->getElementsByTagName('tag1'); if(c

How to parse HTML table using PHP?

Possible Duplicate: How to parse and process HTML with PHP? I need to fetch the second column of the given HTML table using PHP. How can I do it? References: Table to be parsed: http://bit.ly/Ak2xay HTML code of this table: http://bit.ly/ACdLMn For tidy HTML codes, one of the parsing approach can be DOM. DOM divides your HTML code into objects and then allows you to call the desired

如何使用PHP解析HTML表格?

可能重复: 如何使用PHP解析和处理HTML? 我需要使用PHP获取给定HTML表格的第二列。 我该怎么做? 参考文献: 要解析的表:http://bit.ly/Ak2xay 此表的HTML代码:http://bit.ly/ACdLMn 对于整洁的HTML代码,其中一种解析方法可以是DOM。 DOM将您的HTML代码分成对象,然后允许您调用所需的对象及其值/标签名称等。 PHP HTML DOM解析的官方文档可从http://php.net/manual/en/book.dom.php获取 为了在DOM实现之

PHP HTML DOM Parser

Possible Duplicate: How to parse and process HTML with PHP? I'm looking into HTML DOM parsers for PHP. I've found PHP Simple HTML DOM Parser. Are there any others I should be looking at? Yes. Simple html doc is fine, but an order of magnitude slower than the built in dom parser. $dom = new DOMDocument(); @$dom->loadHTML($html); $x = new DOMXPath($dom); foreach($x->query(

PHP HTML DOM解析器

可能重复: 如何使用PHP解析和处理HTML? 我正在研究PHP的HTML DOM解析器。 我找到了PHP Simple DOM DOM Parser。 还有其他我应该看的东西吗? 是。 简单的html文档很好,但比内置的dom解析器慢一个数量级。 $dom = new DOMDocument(); @$dom->loadHTML($html); $x = new DOMXPath($dom); foreach($x->query("//a") as $node) { $data['dom']['href'][] = $node->getAttribute("href"); } 使用它。

elements from string, in PHP

Possible Duplicates: crawling a html page using php? Best methods to parse HTML I have one string-variable in my php-script, that contains html-page. How i can extract DOM-elements from this string? For example, in this string '<div class="someclass">text</div>' , i wish get variable 'text'. How i can do this? You need to use the DOMDocument class

来自字符串的元素,在PHP中

可能重复: 使用PHP爬取一个HTML页面? 解析HTML的最佳方法 我的php-script中有一个字符串变量,它包含html页面。 我如何从这个字符串中提取DOM元素? 例如,在这个字符串'<div class="someclass">text</div>' ,我希望获得变量'text'。 我怎么能做到这一点? 您需要使用DOMDocument类,更具体地说,使用loadHTML方法将HTML字符串加载到DOM对象。 例如 : $string = <&l

HTML Scraping in Php

This question already has an answer here: How do you parse and process HTML/XML in PHP? 28 answers I would recomend PHP Simple HTML DOM Parser after you have scraped the HTML from the page. It supports invalid HTML, and provides a very easy way to handle HTML elements. If the page you're scraping is valid X(HT)ML, then any of PHP's built-in XML parsers will do. I haven't had

在Php中的HTML刮

这个问题在这里已经有了答案: 如何解析和处理PHP中的HTML / XML? 28个答案 在从页面中获取HTML后,我会推荐PHP Simple HTML DOM Parser。 它支持无效的HTML,并提供了一种处理HTML元素的非常简单的方法。 如果您正在抓取的页面是有效的X(HT)ML,那么任何PHP的内置XML解析器都会执行。 我并没有在PHP库中取得很多成功。 如果你冒险,但你可以尝试simplehtmldom。 我建议使用Hpricot for Ruby或美丽的汤来使用Pyth

PHP Parse HTML code

Possible Duplicate: Best methods to parse HTML How can I parse HTML code held in a PHP variable if it something like: <h1>T1</h1>Lorem ipsum.<h1>T2</h1>The quick red fox...<h1>T3</h1>... jumps over the lazy brown FROG! I want to only get the text that's between the headings and I understand that it's not a good idea to use Regular Expressions. U

PHP解析HTML代码

可能重复: 解析HTML的最佳方法 如何解析PHP变量中包含的HTML代码,如果它是这样的: <h1>T1</h1>Lorem ipsum.<h1>T2</h1>The quick red fox...<h1>T3</h1>... jumps over the lazy brown FROG! 我只想获取标题之间的文本,并且我明白使用正则表达式不是一个好主意。 使用PHP文档对象模型: <?php $str = '<h1>T1</h1>Lorem ipsum.<h1>T2</h1>The qu

Best XML Parser for PHP

This question already has an answer here: How do you parse and process HTML/XML in PHP? 28 answers I would have to say SimpleXML takes the cake because it is firstly an extension, written in C, and is very fast. But second, the parsed document takes the form of a PHP object. So you can "query" like $root->myElement . Have a look at PHP's available XML extensions and see

最适合PHP的XML解析器

这个问题在这里已经有了答案: 如何解析和处理PHP中的HTML / XML? 28个答案 我不得不说,SimpleXML需要蛋糕,因为它首先是一个扩展,用C编写,速度非常快。 但其次,解析后的文档采用PHP对象的形式。 所以你可以像“ $root->myElement ” $root->myElement ”一样“查询”。 查看PHP的可用XML扩展,并参阅http://devzone.zend.com/243/和http://devzone.zend.com/1035/以获得有关这些扩展的讨论。 XML解析器和Simpl