Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6877 > unrolled thread
| Started by | SMH <garyconditswellhungrelative@yahooDOT.com> |
|---|---|
| First post | 2012-08-27 04:25 +0000 |
| Last post | 2012-08-27 06:07 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.php
DOMDocument::saveHTML() Method Not Accepting Single Argument SMH <garyconditswellhungrelative@yahooDOT.com> - 2012-08-27 04:25 +0000
Re: DOMDocument::saveHTML() Method Not Accepting Single Argument Adam Harvey <usenet@adamharvey.name> - 2012-08-27 05:09 +0000
Re: DOMDocument::saveHTML() Method Not Accepting Single Argument SMH <garyconditswellhungrelative@yahooDOT.com> - 2012-08-27 06:07 +0000
| From | SMH <garyconditswellhungrelative@yahooDOT.com> |
|---|---|
| Date | 2012-08-27 04:25 +0000 |
| Subject | DOMDocument::saveHTML() Method Not Accepting Single Argument |
| Message-ID | <XnsA0BC4B91261FBSMH1960@88.198.244.100> |
Using PHP 5.2
The DOMDocument object method saveHTML() explains that I can pass a DOMNode
object as an optional parameter and get the string output of just the node.
http://www.php.net/manual/en/domdocument.savehtml.php
I have verified that the object I am passing to the method is a DOMElement
object, a type of DOMNode.
I keep getting the warning:
Warning: DOMDocument::saveHTML() expects exactly 0 parameters,
1 given in <php script document>
Is this a bug?
Commentary below does not even address the use of the method with the
optional argument.
====
What do I want to do??
I have DOM elements with mostly one child node of type DOMText representing
file names, and I use 'textContent' property to get the string representing
the file name.
However, some filenames contained characters, like '&', and I had to use
method DOMDocument:createEntityReference() to append them as child nodes to
the element.
But when I try to retrieve with 'textContent' property, only child nodes of
type DOMText are returned concatenated, not entity references.
I figured saveHTML([DOMElement]) might fix this.
[toc] | [next] | [standalone]
| From | Adam Harvey <usenet@adamharvey.name> |
|---|---|
| Date | 2012-08-27 05:09 +0000 |
| Message-ID | <k1evdn$7li$1@dont-email.me> |
| In reply to | #6877 |
On Mon, 27 Aug 2012 04:25:49 +0000, SMH wrote:
> Using PHP 5.2
>
> I keep getting the warning:
>
> Warning: DOMDocument::saveHTML() expects exactly 0 parameters,
> 1 given in <php script document>
>
>
>
> Is this a bug?
The manual page you linked to has a changelog, which indicates that the
parameter was added in PHP 5.3.6.
> However, some filenames contained characters, like '&', and I had to use
> method DOMDocument:createEntityReference() to append them as child nodes
> to the element.
Why? If you're adding the text as text nodes, there's no need to
explicitly create entity references: $doc->createTextNode('foo&bar');
results in a valid text node which will be saved as "foo&bar" when
save() or saveXML() are called.
> But when I try to retrieve with 'textContent' property, only child nodes
> of type DOMText are returned concatenated, not entity references.
Entity references aren't text content, at least as far as libxml and PHP
are concerned.
> I figured saveHTML([DOMElement]) might fix this.
It may, but not until you use a version of PHP that supports it. :)
Adam
[toc] | [prev] | [next] | [standalone]
| From | SMH <garyconditswellhungrelative@yahooDOT.com> |
|---|---|
| Date | 2012-08-27 06:07 +0000 |
| Message-ID | <XnsA0BC5CDE2855ESMH1960@88.198.244.100> |
| In reply to | #6879 |
Adam Harvey <usenet@adamharvey.name> wrote on Mon 27 Aug 2012 08:09:11a
> On Mon, 27 Aug 2012 04:25:49 +0000, SMH wrote:
>> Using PHP 5.2
>>
>> I keep getting the warning:
>>
>> Warning: DOMDocument::saveHTML() expects exactly 0 parameters,
>> 1 given in <php script document>
>>
>>
>>
>> Is this a bug?
>
> The manual page you linked to has a changelog, which indicates that the
> parameter was added in PHP 5.3.6.
>
>> However, some filenames contained characters, like '&', and I had to use
>> method DOMDocument:createEntityReference() to append them as child nodes
>> to the element.
>
> Why? If you're adding the text as text nodes, there's no need to
> explicitly create entity references: $doc->createTextNode('foo&bar');
> results in a valid text node which will be saved as "foo&bar" when
> save() or saveXML() are called.
>
>> But when I try to retrieve with 'textContent' property, only child nodes
>> of type DOMText are returned concatenated, not entity references.
>
> Entity references aren't text content, at least as far as libxml and PHP
> are concerned.
>
>> I figured saveHTML([DOMElement]) might fix this.
>
> It may, but not until you use a version of PHP that supports it. :)
Thanks, Adam.
I think I resorted to using it because of some error or other warning I got
with special HTML characters, and it probably applied to THAT situation, but
clearly not to THIS situation; over-thinking, I guess.
Your explanations resulted in warning-free code.
I'll remember to read the changelog too to make sure that the syntax applies
to the current version. I use 5.2 because I think that is the latest
version produced as a ready binary for Win 7 running Apache 2.2, but then
again, I could certainly even be wrong on that as well. :)
> Adam
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web