simple-html-dom

PHP Simple HTML DOM Parser: Select only DIVs with multiple classes

廉价感情. 提交于 2019-11-29 18:31:13
问题 I was searching like mad and found no solution. The problem is simple. Let's say I have 3 DIVs: <div class="class1"> <div class="subclass"> TEXT1 </div> </div> <div class="class2"> <div class="subclass"> TEXT2 </div> </div> <div class="class1 class2"> <div class="subclass"> TEXT3 </div> </div> So, very simple. I just want to find the TEXT3, which has BOTH class1 and class2. Using Simple HTML DOM Parser, I can't seem to get it to work. Here's what I tried: foreach($html->find("[class=class1],

PHP Simple Html Dom get the plain text of div,but avoiding all other tags

大憨熊 提交于 2019-11-29 15:07:14
I use PHP Simple Html Dom to get some html,now i have a html dom like follow code,i need fetch the plain text inner div,but avoiding the p tags and their content(only return 111111), who can help me?Thanks in advance! <div> <p>00000000</p> 111111 <p>22222222</p> </div> It depends on what you mean by "avoiding the p tags". If you just want to remove the tags, then just running strip_tags() on it should work for what you want. If you actually want to just return "11111" (ie. strip the tags and their contents ) then this isn't a viable solution. For that, something like this may work: $myDiv =

Find text inside javascript tag using PHP Simple HTML DOM Parser

China☆狼群 提交于 2019-11-29 13:09:30
I'm trying to find a text change regularly inside javascript tag : <script type="text/javascript"> jwplayer("mediaplayer").setup({ flashplayer: "player.swf", file:"filename", provider: "rtmp", streamer:"rtmp://192.168.1.1/file?wmsAuthSign=RANDOM-114-Character==", height:500, width:500, }); </script> How to get RANDOM-114-Character (or full value of 'streamer' flashvars) using PHP Simple HTML DOM Parser, I just have no idea to do this. You can do it with regular expression: preg_match ($pattern, $java_script, $matches); Pattern depends, if the variable 'wmsAuthSign' is unique. For example:

How should parse with PHP (simple html dom parser) background images and other images of webpage?

北慕城南 提交于 2019-11-29 12:53:12
How should parse with PHP (simple html dom/etc..) background and other images of webpage? case 1: inline css <div id="id100" style="background:url(/mycar1.jpg)"></div> case 2: css inside html page <div id="id100"></div> <style type="text/css"> #id100{ background:url(/mycar1.jpg); } </style> case 3: separate css file <div id="id100" style="background:url(/mycar1.jpg);"></div> external.css #id100{ background:url(/mycar1.jpg); } case 4: image inside img tag solution to case 4 as he appears in php simple html dom parser : // Create DOM from URL or file $html = file_get_html('http://www.google.com/

php simple html dom parse img html5 attributes?

我怕爱的太早我们不能终老 提交于 2019-11-29 03:45:54
How to use simple html dom parse img html5 attribute: data-original $htmls = '<img class="lazy" alt="Nubifragio a Verbania , ferite 2 turiste Gravi danni, chiesto stato di calamità foto" title="Nubifragio a Verbania , ferite 2 turiste Gravi danni, chiesto stato di calamità foto" data-original="http://www.repubblica.it/images/2012/08/26/130634575-506cc9ae-11b8-4a53-920c-539a3811e46b.jpg" src="http://www.repubblica.it/static/images/homepage/2012/lazy.png" width="130" height="98" style="display: inline; ">'; $html = str_get_html($htmls); $fata = $html->find('img'); foreach($fata as $newimage){

PHP HTML DOM Parser [duplicate]

被刻印的时光 ゝ 提交于 2019-11-29 03:19:16
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("//a") as $node) { $data['dom']['href'][] = $node->getAttribute("href"); } Use that. You can look at the builtin DOM http://php.net/dom Recently I also found ganon , but in general PHP Simple HTML DOM Parser is the best! 来源:

How to extract complete sub links using Simple-HTML-DOM?

流过昼夜 提交于 2019-11-28 12:22:44
问题 The following is the basic code I use to extract sublinks from a page: <?php include_once('simple_html_dom.php'); function extract_links($target_url) { $html = new simple_html_dom(); $html->load_file($target_url); $i=0; $crawl =array(); foreach($html->find('a') as $link) { $crawl[$i] = $link->href; $i++; } var_dump($crawl); } extract_links('http://stackoverflow.com'); ?> The output is as follows: array 0 => string 'http://stackexchange.com' (length=24) 1 => string '/users/login' (length=12) 2

Using SimpleHtmlDom, how to remove and replace a specific attribute

こ雲淡風輕ζ 提交于 2019-11-28 11:34:59
问题 I'm currently using this HTML DOM PARSER using php : http://simplehtmldom.sourceforge.net/ I'm confused on how to remove and replace the selected attribute href="style.css" , I want to replace the link with "index/style.css" , should I insert only the index/ or replace the whole attribute from the whole html code? 回答1: This should do it: $doc = str_get_html($code); foreach ($doc->find('a[href]') as $a) { $href = $a->href; if (/* $href begins with a relative URL path */) { $a->href = 'index/'.

how to print cells of a table with simple html dom

自古美人都是妖i 提交于 2019-11-28 11:14:56
i have this html code. Im using Simple HTML Dom to parse the data into my own php script. <table> <tr> <td class="header">Name</td> <td class="header">City</td> </tr> <tr> <td class="text">Greg House</td> <td class="text">Century City</td> </tr> <tr> <td class="text">Dexter Morgan</td> <td class="text">Miami</td> </tr> </table> I need to get the text inside the TDs in an array, example: $array[0] = array('Greg House','Century City'); $array[1] = array('Dexter Morgan','Miami'); I've tried several ways to get that but i've fail in each and everyone of them. Can someone give me a hand? This

PHP Simple Html Dom get the plain text of div,but avoiding all other tags

冷暖自知 提交于 2019-11-28 08:20:17
问题 I use PHP Simple Html Dom to get some html,now i have a html dom like follow code,i need fetch the plain text inner div,but avoiding the p tags and their content(only return 111111), who can help me?Thanks in advance! <div> <p>00000000</p> 111111 <p>22222222</p> </div> 回答1: It depends on what you mean by "avoiding the p tags". If you just want to remove the tags, then just running strip_tags() on it should work for what you want. If you actually want to just return "11111" (ie. strip the tags