quite a big bug in DOM

php.internals

Ron Korving

20 years ago
Hi, I found a bug in DOM. It surprises me that it's never been seen and/or fixed before. I can't find anything about in the PHP bugtracker anyway. The reason why I'm posting here and not writing a bugreport, is because I'm not sure if this is a problem in the PHP-extension or the DOM-library itself. In the latter case there's nothing anybody here can do, I guess. This is the situation: <?php $doc = DOMDocument::loadHTML('<html><body>&nbsp;</body></html>'); echo "'".$doc->getElementsByTagName('body')->item(0)->textContent."'\n"; $doc = DOMDocument::loadHTML('<html><body>foo&nbsp;bar</body></html>'); echo "'".$doc->getElementsByTagName('body')->item(0)->textContent."'\n"; ?> Output: ' ' 'foo bar' Where the heck do these 'Â's come from when it parses an &nbsp; ? I hope anyone can shed some light on the next step to be taken in order to fix this. Thanks, Ron Korving

Ron Korving

20 years ago
To make it extra clear, what is outputted where the &nbsp; is are 2 bytes: ascii codes 194 and 160. The 160 is the spacing character that is expected, but the 194 (the letter A with a ^ on top) is pretty magical and annoying. Some other (but not all) HTML-characters (e.g. &euml;) seem to have the same problem, but they output other bad characters. I've tried playing with a <head><meta http-equiv="Content-Type" content="text/html; charset=utf8"></head> in the HTML-data while changing the characterset, but nothing changed. Ron ""Ron Korving"" <r.korving@xit.nl> schreef in bericht news:C3.72.43379.31D7A234@pb1.pair.com...
> Hi, > > I found a bug in DOM. It surprises me that it's never been seen and/or
fixed
> before. I can't find anything about in the PHP bugtracker anyway. The
reason
> why I'm posting here and not writing a bugreport, is because I'm not sure
if

messju mohr

20 years ago
On Fri, Sep 16, 2005 at 10:06:40AM +0200, Ron Korving wrote:
> Hi, > > I found a bug in DOM. It surprises me that it's never been seen and/or fixed > before. I can't find anything about in the PHP bugtracker anyway. The reason > why I'm posting here and not writing a bugreport, is because I'm not sure if > this is a problem in the PHP-extension or the DOM-library itself. In the > latter case there's nothing anybody here can do, I guess. > > This is the situation: > > <?php > $doc = DOMDocument::loadHTML('<html><body>&nbsp;</body></html>'); > echo "'".$doc->getElementsByTagName('body')->item(0)->textContent."'\n"; > > $doc = DOMDocument::loadHTML('<html><body>foo&nbsp;bar</body></html>'); > echo "'".$doc->getElementsByTagName('body')->item(0)->textContent."'\n"; > ?> > > Output: > > ' ' > 'foo bar' > > Where the heck do these 'Â's come from when it parses an &nbsp; ? I hope > anyone can shed some light on the next step to be taken in order to fix > this.
not a bug. the two bytes 'Â ' are an utf8-encoded nbsp. recode it, or tell your output device to display utf8-encoded strings properly. greetings

Ron Korving

20 years ago
""messju mohr"" <messju@lammfellpuschen.de> schreef in bericht news:20050916083351.GF1577@dune... A thank you to you as well. In general: By the way, wouldn't it be time for trim() to start trimming off ascii characters 160 too since that's what &nbsp; represents? It's no biggy, but maybe something to consider. Ron

Christian Stocker

20 years ago
On 16.9.2005 10:06 Uhr, Ron Korving wrote:
> Hi, > > I found a bug in DOM. It surprises me that it's never been seen and/or fixed > before. I can't find anything about in the PHP bugtracker anyway. The reason > why I'm posting here and not writing a bugreport, is because I'm not sure if > this is a problem in the PHP-extension or the DOM-library itself. In the > latter case there's nothing anybody here can do, I guess. > > This is the situation: > > <?php > $doc = DOMDocument::loadHTML('<html><body>&nbsp;</body></html>'); > echo "'".$doc->getElementsByTagName('body')->item(0)->textContent."'\n"; > > $doc = DOMDocument::loadHTML('<html><body>foo&nbsp;bar</body></html>'); > echo "'".$doc->getElementsByTagName('body')->item(0)->textContent."'\n"; > ?> > > Output: > > ' ' > 'foo bar'
No bug, please check your encoding. It's utf-8 and your terminal has a problem with it.. chregu
> > Where the heck do these 'Â's come from when it parses an &nbsp; ? I hope > anyone can shed some light on the next step to be taken in order to fix > this. > > Thanks, > > Ron Korving >
-- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | christian.stocker@bitflux.ch | GPG 0x5CE1DECB

Ron Korving

20 years ago
Damn.. I feel stupid now... Sorry guys. Is it normal for DOM to output everything in UTF8 without an ability to influence this? I figured that it wouldn't be a UTF8 problem because it outputs 2 bytes, and I thought UTF8 was just 1 byte (hence the name UTF8). Guess I was wrong. Sorry again, I really hate to create a fuss about something when it's my own fault. Ron
> No bug, please check your encoding. It's utf-8 and your terminal has a > problem with it.. > > chregu
________________________________________ Scanned and protected by SecureMail v2.2 http://www.axit.nl

Derick Rethans

20 years ago
On Fri, 16 Sep 2005, Ron Korving wrote:
> Damn.. I feel stupid now... Sorry guys. > Is it normal for DOM to output everything in UTF8 without an ability to > influence this?
Yes.
> I figured that it wouldn't be a UTF8 problem because it > outputs 2 bytes, and I thought UTF8 was just 1 byte (hence the name UTF8). > Guess I was wrong.
Yeah, in UTF8 a character can be 1, 2, 3, or 4 bytes. http://derickrethans.nl/files/wereldveroverend-ac2005.pdf, from slide 7 onwards. Derick
-- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org

Pierre Joye

20 years ago
On 9/16/05, Ron Korving <r.korving@xit.nl> wrote:
> Damn.. I feel stupid now... Sorry guys. > Is it normal for DOM to output everything in UTF8 without an ability to > influence this?
For the record, DOM does not output anything using UTF-8, it does convert the input to UTF-8. It's a slighty different thing. --Pierre