The Code is as follows: {code ...} & amp; lt; br & amp; gt; In the content will be removed. You can retain html tags for any operations such as $ e-& amp; gt; innerHtml. 8.18 update: {code...} the code is as follows:
$html = <<
Test
abcdefghijklmn
opqrstuvwxyz
EOF;// create document object model$dom = new DOMDocument();// load html into document object model@$dom->loadHTML($html);// create domxpath instance$xPath = new DOMXPath($dom);// get all elements with a particular id and then loop through and print the href attribute$elements = $xPath->query('//*[@id="content"]/p/span');$content = $elements->item(0)->nodeValue;echo $content;
Content
Will be removed. html tags can be retained for any operations such as $ e-> innerHtml.
8.18 update:
$html = <<
Test
abcdefghijklmn
opqrstuvwxyz
EOF;// create document object model$dom = new DOMDocument();// load html into document object model@$dom->loadHTML($html);// create domxpath instance$xPath = new DOMXPath($dom);// get all elements with a particular id and then loop through and print the href attribute$elements = $xPath->query('//*[@id="content"]/p/span');$nodeName = $elements->item(0)->nodeName;// $content = $elements->item(0)->nodeValue;$content = $dom->saveXml($elements->item(0));$content = $dom->saveHtml($elements->item(0));$content = preg_replace(array("#^<{$nodeName}.*>#isU", "#
$#isU"), array('', ''), $content);echo $content;
Reply content:
The Code is as follows:
$html = <<
Test
abcdefghijklmn
opqrstuvwxyz
EOF;// create document object model$dom = new DOMDocument();// load html into document object model@$dom->loadHTML($html);// create domxpath instance$xPath = new DOMXPath($dom);// get all elements with a particular id and then loop through and print the href attribute$elements = $xPath->query('//*[@id="content"]/p/span');$content = $elements->item(0)->nodeValue;echo $content;
Content
Will be removed. html tags can be retained for any operations such as $ e-> innerHtml.
8.18 update:
$html = <<
Test
abcdefghijklmn
opqrstuvwxyz
EOF;// create document object model$dom = new DOMDocument();// load html into document object model@$dom->loadHTML($html);// create domxpath instance$xPath = new DOMXPath($dom);// get all elements with a particular id and then loop through and print the href attribute$elements = $xPath->query('//*[@id="content"]/p/span');$nodeName = $elements->item(0)->nodeName;// $content = $elements->item(0)->nodeValue;$content = $dom->saveXml($elements->item(0));$content = $dom->saveHtml($elements->item(0));$content = preg_replace(array("#^<{$nodeName}.*>#isU", "#
$#isU"), array('', ''), $content);echo $content;
You have found a solution...
$ Content = $ elements-> item (0)-> nodeValue; // >>>>$ content = $ dom-> saveXml ($ elements-> item (0 ));