|
It was suggested to me that in order to close some "dangling" HTML tags, I should use PHP's DOM extension and loadHTML.
I've been trying for a while, searching for tutorials, reading this page , trying various things, but can't seem to figure out how ...
Started by Jeff on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I think you're following the wrong approach: You have to use the DOM stuff to truncate the string, not after using the DOMDocument::loadHTML....
Sure you could get DOM to do what you want I'm pretty sure you'd be better off with Tidy .
|
|
$html = file_get_contents("http://www.somesite.com/"); $dom = new DOMDocument(); $dom->loadHTML($html); echo $dom;
throws
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, Catchable fatal error: Object of class DOMDocument...
Started by gweg on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
You're probably looking for
echo $....
What were you expecting to see not be echo'ed.
Manual/en/language.operators.errorcontrol.php )
$dom->@loadHTML($html);
$dom is an object, not a string, and you can't just echo $dom.
|
|
Hi!
I use the following to get a html document into DOM:
$dom = new domDocument('1.0', 'utf-8'); $dom->loadHTML($html)
and then I add some new content to an element in the html:
$element = $dom->getElementById('mybox'); $f = $dom->createDocumentFragment...
Started by Tommy on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
(There is also Element.setIdAttribute which can be used to declare one instance.)
I haven't tested this though and it wouldn't surprise me if PHP didn't implement this DOM Level 3 Core type definition already automatically....
ID) by loadHTML .
|
Ask your Facebook Friends
|
$dom = new DOMDocument(); $dom->loadHTML($string); $dom->preserveWhiteSpace = false; $elements = $dom->getElementsByTagName('span'); $spans = array(); foreach($elements as $span) { $spans[] = $span; } foreach($spans as $span) { $span->parentNode...
Started by ile on
, 5 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Try to set the encoding in the constructor or with DOMDocument->encoding :
$dom = new DOMDocument('1.0', '…'); // or $dom = new DOMDocument(); $dom->encoding = '…';
this $dom->encoding;"], $trans["&"]); echo strtr....
|
|
$string = file_get_contents('http://example.com'); if ('UTF-8' === mb_detect_encoding($string)) { $dom = new DOMDocument(); // hack to preserve UTF-8 characters $dom->loadHTML('<?xml encoding="UTF-8">' . $string); $dom->preserveWhiteSpace ...
Started by Richard Knop on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Loading the html
$string = mb_convert_encoding($string, 'HTML-ENTITIES', "UTF-8"); $dom->loadHTMLIn case it is definitely the DOM screwing up the encoding, this trick did it for me a while back but you can still try:
$dom = new....
|
|
<? $string = ' Some photos<br> <span class="naslov_slike">photo_by_ile_IMG_1676-01</span><br /> <span class="naslov_slike">photo_by_ile_IMG_1699-01</span><br /> <span class="naslov_slike">photo_by_ile...
Started by ile on
, 4 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
PreserveWhiteSpace = false; $dom->loadHTML($string); $elements = $dom->getElementsByTagName that first bit out:
echo preg_replace("/<!DOCTYPE [^>]+>/", "", $dom->saveHTML());
I'm;p> around the text node....
|
|
Hello
I have the following code to retrieve all hyper links in an HTML document
and my question is how to retrieve the text nodes inside every anchor tag
(even if the text node is a child of a child like if the anchor node has a span node which has a ...
Started by ahmed on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Anchor->textContent
A slightly more info here DOMNode->textContent
:D
Heres what you can do:
(string)$anchor->nodeValue;
As referenced in the DomDocument::DomNode page .
|
|
So let's say the HTML looks something like this:
<select name="some_name"> <option value="1">1</option> <option value="2">2</option> <option value="3" selected="selected">3</option> <option value="4">4<...
Started by Richard Knop on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Selected"
$num = 0; $optionTags = $dom->getElementsByTagName('option'); for ($i = 0; $i <nodeValue; } }
EDIT: My exact code:
$dom = new DOMDocument(); $dom->load("C:\\test.htm"); $num = 0; $optionTags = $dom->....
|
|
Can someone explain to me what is nodeValue in this and write out how nodeValue look like or write out what's in nodeValue? EDIT: Sorry! Yes, this is PHP.
And..
foreach ($elements as $e) { echo $e->nodeValue; }
What does the arrow thingy mean (->...
Started by Doug on
, 3 posts
by 2 people.
Answer Snippets (Read the full thread at stackoverflow):
From http://website.com , loading it into a DOM Document (Document Object Model), and then performing.
|
|
Hello,
I am using PHP's DOM object to create HTML pages for my website. This works great for my head, however since I will be entering a lot of HTML into the body (not via DOM). I would think I would need to use DOM->createElement($bodyHTML) to add...
Started by mrlanrat on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
" </body>"); // this would even work;"; /....
$bodyHTML.
<?php $dom = new DOMDocument(); $dom->loadHTML("<font color='red I might add"; $dom->loadHTML("<body> " .
loadHTML works just fine.
|