domparser

Parse anchor tags which have img tag as child element

爷,独闯天下 提交于 2019-12-03 20:15:43
I need to find all anchor tags, which have an img tag as child element. Consider the following cases, <a href="test1.php"> <img src="test1.jpg" alt="Test 1" /> </a> <a href="test2.php"> <span> <img src="test2.jpg" alt="Test 2" /> </span> </a> My requirement is to generate a list of href attributes along with src and alt ie, $output = array( array( 'href' => 'test1.php', 'src' => 'test1.jpg', 'alt' => 'Test 1' ), array( 'href' => 'test2.php', 'src' => 'test2.jpg', 'alt' => 'Test 2' ) ); How can I match the above cases in PHP? (Using Dom Xpath or any other dom parser) Thanks in Advance! Assuming

Preserve Line Breaks - Simple HTML DOM Parser

£可爱£侵袭症+ 提交于 2019-12-03 04:15:32
问题 When using PHP Simple HTML DOM Parser, is it normal that line breaks tags are stripped out? 回答1: I know this is old, but I was looking for this as well, and realized there was actually a built in option to turn off the removal of line breaks. No need to go editing the source. The PHP Simple HTML Dom Parser's load function supports multiple useful parameters: load($str, $lowercase=true, $stripRN=false, $defaultBRText=DEFAULT_BR_TEXT) When calling the load function, simply pass false as the

Preserve Line Breaks - Simple HTML DOM Parser

巧了我就是萌 提交于 2019-12-02 17:35:06
When using PHP Simple HTML DOM Parser, is it normal that line breaks tags are stripped out? I know this is old, but I was looking for this as well, and realized there was actually a built in option to turn off the removal of line breaks. No need to go editing the source. The PHP Simple HTML Dom Parser's load function supports multiple useful parameters: load($str, $lowercase=true, $stripRN=false, $defaultBRText=DEFAULT_BR_TEXT) When calling the load function, simply pass false as the third parameter. $html = new simple_html_dom(); $html->load("<html><head></head><body>stuff</body></html>",

How to Parse XML file Using Dom Parsing?

戏子无情 提交于 2019-12-02 14:12:37
My Problem is I am Using Dom Parsing to parse below xml file but this give me error of NullPointerException. Any Help Would be Appreciated. MainActivity.java public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ScrollView mScrView1 = new ScrollView(this); /** Create a new layout to display the view */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(1); /** Create a new textview array to display the results */ TextView id[]; TextView published[]; TextView content[]; TextView title[];

Text replacement: PHP/regex

若如初见. 提交于 2019-12-02 10:22:14
问题 I am presented with an HTML document similar to this in view source mode (the below is simplified for brevity): <html> <head> <title>System version: {{variable:system_version}}</title> </head> <body> <p>You are using system version {{variable:system_version}}</p> {{block:welcome}} <form> <input value="System version: {{variable:system_version}}"> <textarea> You are using system version {{variable:system_version}}. </textarea> </form> </body> </html> I have written some functions that can

Text replacement: PHP/regex

[亡魂溺海] 提交于 2019-12-02 07:05:47
I am presented with an HTML document similar to this in view source mode (the below is simplified for brevity): <html> <head> <title>System version: {{variable:system_version}}</title> </head> <body> <p>You are using system version {{variable:system_version}}</p> {{block:welcome}} <form> <input value="System version: {{variable:system_version}}"> <textarea> You are using system version {{variable:system_version}}. </textarea> </form> </body> </html> I have written some functions that can replace these {{...}} type strings, but they need to be replaced selectively. In the example above, I want

DOMParser injects DOM but does not apply css stylesheets once injected?

孤者浪人 提交于 2019-11-30 20:24:31
I have a little testcase over at: http://jsfiddle.net/9xwUx/1/ The code boils down to the following (given a node with id "target"): var string = '<div class="makeitpink">this should be pink, but is not</div>'; var parser = new DOMParser(); var domNode = parser.parseFromString(string,"text/xml"); document.getElementById("target").appendChild(domNode.firstChild); If you run the testcase, and then inspect the target node via firebug/chrome web inspector and select any node within the body tag of jsfiddle's iframe, and do "edit as HTML", add a random charachter anywhere as a string [not an

Simple HTML DOM Parser - Send post variables

。_饼干妹妹 提交于 2019-11-30 17:43:34
问题 I have the Simple HTML DOM Parser for PHP, and I am using the following markup: $html = file_get_html('http://www.google.com'); However how do I send post variables (like a cURL) to that page and get the response? For example $html = file_get_html('http://www.google.com', array("Item"=>"Value", "Item2"=>"Value2")); 回答1: The documentation doesn't mention it as far as I can see, but after taking a look in the source code I noticed the function you're using accepts a stream context as its third

How to create DOM object from html page received over XMLHttpRequest?

依然范特西╮ 提交于 2019-11-30 10:47:52
I'm developing a chromium extension so I have cross-host permissions for XMLHttpRequests for the domains I'm asking permissions for. I have used XMLHttpRequest and got an HTML webpage (txt/html). I want to use XPath (document.evaluate) to extract relevant bits from it. Unfortunatly I'm failing to construct a DOM object from the returned string of the html. var xhr = new XMLHttpRequest(); var name = escape("Sticks N Stones Cap"); xhr.open("GET", "http://items.jellyneo.net/?go=show_items&name="+name+"&name_type=exact", true); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { var

DOMParser injects DOM but does not apply css stylesheets once injected?

一世执手 提交于 2019-11-30 05:07:31
问题 I have a little testcase over at: http://jsfiddle.net/9xwUx/1/ The code boils down to the following (given a node with id "target"): var string = '<div class="makeitpink">this should be pink, but is not</div>'; var parser = new DOMParser(); var domNode = parser.parseFromString(string,"text/xml"); document.getElementById("target").appendChild(domNode.firstChild); If you run the testcase, and then inspect the target node via firebug/chrome web inspector and select any node within the body tag