simple-html-dom

Adjust Image if page break occurs in mpdf library

戏子无情 提交于 2019-12-25 02:28:18
问题 I am generating pdf from html source using mpdf library in php and everything seems working perfect. Now I have an issue with the images. Suppose before page end I'm inserting an image but image is big so that it doesn't fit at the bottom of first page and goes to second page. Now I have a long white space at the end of first page because image moved to second page. Now I want is "if next item to insert in pdf is an image then calculate the remaining size of pdf page if it is less than Image

Simple HTML DOM str_replace on plain text

拥有回忆 提交于 2019-12-25 02:09:59
问题 I am trying to create something where it will change all of the text on a webpage and re output it to the user. It will be changing words predefined in a database. I am using http://simplehtmldom.sourceforge.net as my HTML parser. What i want todo is to change only the test inside of tags but not the tags. I thought this would work, If i echo out $e->plaintext it will work but then it isn't styled. <?php // example of how to modify HTML contents include('../simple_html_dom.php'); // get DOM

Html Dom parser get first element

房东的猫 提交于 2019-12-24 22:01:26
问题 Hi i'm using simple_html_dom php library to get contents from other website. I have below html structure, <h1 class="nik_product_title" style="color: #000;"> DSLR D7100 <span class="new_big_parent"> <span class="new_big_child"> <span class="new_big_child1">new</span> </span> </span> </h1> Using this @$html->find ( 'div[class=nik_block_product_main_info_component_inner] h1',0)->plaintext; But i'm getting output as DSLR+D7100new How to get only first plain text i.e, need to fetch only DSLR

PHP simplehtmldom adding attributes

依然范特西╮ 提交于 2019-12-24 13:54:45
问题 For a project, I need to grab a page (ANY page on the internet) and manipulate it. I am using simplehtmldom for this (found here), since it is easy and works like a charm.. mostly.. I need to set a class attribute to certain elements, some of which do have a class attribute already, some of which don't. According to this article i found, you can add an attribute the following way: $value = $e->attr['data-role']; This, unfortunately, does not work for me. The following code gives these errors:

Add html tag to string in PHP

寵の児 提交于 2019-12-24 04:44:07
问题 I would like to add html tag to string of HTML in PHP, for example: <h2><b>Hello World</b></h2> <p>First</p> Second <p>Third</p> Second is not wrapped with any html element, so system will add p tag into it, expected result: <h2><b>Hello World</b></h2> <p>First</p> <p>Second</p> <p>Third</p> Tried with PHP Simple HTML DOM Parser but have no clue how to deal with it, here is my example of idea: function htmlParser($html) { foreach ($html->childNodes() as $node) { if ($node->childNodes()) {

PHP Simple HTML DOM, Notice: Trying to get property of non-object

谁说我不能喝 提交于 2019-12-23 15:53:31
问题 I am getting Notice: Trying to get property of non-object at: $var = trim($article->find('span[id$=qty]', 0)->innertext); $article is a simple_html_dom() object. 回答1: Maybe span[id$=qty] evaluates to null; means: no node was found. 来源: https://stackoverflow.com/questions/6003991/php-simple-html-dom-notice-trying-to-get-property-of-non-object

Simple HTML DOM - Child Selectors (CSS)

旧城冷巷雨未停 提交于 2019-12-23 10:54:29
问题 I am trying to select a (direct) child of parents div.element using the > combinator, but it's failing. HTML: <div class="element"> <p>test</p> </div> <div class="element"> <div class="selected"> <p>test2</p> </div> </div> PHP: $html->find('div.element > p', 0); I am looking to select the direct p element. If it's a nested descendant - it shouldn't return anything, but it returns test2 . How can I write it to return test , but not test2 ? Thanks UPDATE: The general consensus here on SO seems

Simple HTML DOM - Child Selectors (CSS)

我是研究僧i 提交于 2019-12-23 10:53:05
问题 I am trying to select a (direct) child of parents div.element using the > combinator, but it's failing. HTML: <div class="element"> <p>test</p> </div> <div class="element"> <div class="selected"> <p>test2</p> </div> </div> PHP: $html->find('div.element > p', 0); I am looking to select the direct p element. If it's a nested descendant - it shouldn't return anything, but it returns test2 . How can I write it to return test , but not test2 ? Thanks UPDATE: The general consensus here on SO seems

simple html dom and text

若如初见. 提交于 2019-12-23 05:41:41
问题 suppose that a simple html dom object includes the following text1 <br /> <br /> <br /> text2 <br /> How can i get either of texts using simple html dom? 回答1: To grab all plain text elements, you can use the following: $string="text1 <br /> <br /> <br /> text2 <br />"; $html = str_get_html($string); $texts=$html->find('text'); foreach($texts as $elem_index => $text){ echo $elem_index."=>".$text."<br>"; } Your output should look something like this: 0=>text1 1=> 2=> 3=> text2 In the foreach

simple html dom and text

China☆狼群 提交于 2019-12-23 05:41:25
问题 suppose that a simple html dom object includes the following text1 <br /> <br /> <br /> text2 <br /> How can i get either of texts using simple html dom? 回答1: To grab all plain text elements, you can use the following: $string="text1 <br /> <br /> <br /> text2 <br />"; $html = str_get_html($string); $texts=$html->find('text'); foreach($texts as $elem_index => $text){ echo $elem_index."=>".$text."<br>"; } Your output should look something like this: 0=>text1 1=> 2=> 3=> text2 In the foreach