FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Problem with appendChild and ellipsis...
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Problem with appendChild and ellipsis... [message #173070] Sun, 20 March 2011 14:49 Go to next message
Dennis is currently offline  Dennis
Messages: 17
Registered: February 2004
Karma: 0
Junior Member
When writing a DOMDocument I have code similar to this...

$title = $doc->createElement("title");
$item->appendChild($title);

$title_data = "Some data followed by an ellipsesĀ…";

$title_text = $doc->createTextNode($title_data);
$title->appendChild($title_text);

When I look at the resulting file the <title></title> is there but it is
empty. I displayed $title_text->wholeText and the string with the
ellipsis is there. So it appears that something in appendChild is
gagging on the ellipsis.

Any thoughts?

I wonder if there are other characters that might cause a problem.

--

Dennis
Re: Problem with appendChild and ellipsis... [message #173071 is a reply to message #173070] Sun, 20 March 2011 17:37 Go to previous messageGo to next message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma: 0
Member
In article <ag4co61ltlt2muitdkoup5uufqomlaegg7(at)4ax(dot)com>, Dennis <nobody(at)nowhere(dot)invalid> wrote:
> When writing a DOMDocument I have code similar to this...
>
> $title = $doc->createElement("title");
> $item->appendChild($title);
>
> $title_data = "Some data followed by an ellipses…";
>
> $title_text = $doc->createTextNode($title_data);
> $title->appendChild($title_text);
>
> When I look at the resulting file the <title></title> is there but it is
> empty. I displayed $title_text->wholeText and the string with the
> ellipsis is there. So it appears that something in appendChild is
> gagging on the ellipsis.
>
> Any thoughts?

Ask in an appropriate group. This has *nothing* to do with PHP.

Comp.lang.javascript is --------------> over that way.
Re: Problem with appendChild and ellipsis... [message #173074 is a reply to message #173071] Sun, 20 March 2011 17:12 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/20/2011 1:37 PM, Doug Miller wrote:
> In article<ag4co61ltlt2muitdkoup5uufqomlaegg7(at)4ax(dot)com>, Dennis<nobody(at)nowhere(dot)invalid> wrote:
>> When writing a DOMDocument I have code similar to this...
>>
>> $title = $doc->createElement("title");
>> $item->appendChild($title);
>>
>> $title_data = "Some data followed by an ellipsesā€¦";
>>
>> $title_text = $doc->createTextNode($title_data);
>> $title->appendChild($title_text);
>>
>> When I look at the resulting file the<title></title> is there but it is
>> empty. I displayed $title_text->wholeText and the string with the
>> ellipsis is there. So it appears that something in appendChild is
>> gagging on the ellipsis.
>>
>> Any thoughts?
>
> Ask in an appropriate group. This has *nothing* to do with PHP.
>
> Comp.lang.javascript is --------------> over that way.

Ah, Doug, this IS PHP - not javascript.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Problem with appendChild and ellipsis... [message #173075 is a reply to message #173070] Sun, 20 March 2011 17:14 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/20/2011 10:49 AM, Dennis wrote:
> When writing a DOMDocument I have code similar to this...
>
> $title = $doc->createElement("title");
> $item->appendChild($title);
>
> $title_data = "Some data followed by an ellipsesā€¦";
>
> $title_text = $doc->createTextNode($title_data);
> $title->appendChild($title_text);
>
> When I look at the resulting file the<title></title> is there but it is
> empty. I displayed $title_text->wholeText and the string with the
> ellipsis is there. So it appears that something in appendChild is
> gagging on the ellipsis.
>
> Any thoughts?
>
> I wonder if there are other characters that might cause a problem.
>

I've never seen a problem like this, but then I can't say whether I've
used ellipses or not (if I have, it hasn't been a problem).

Can you post the actual code which is failing (or, if it's too long, a
complete example of the failure)?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Problem with appendChild and ellipsis... [message #173077 is a reply to message #173075] Sun, 20 March 2011 18:24 Go to previous messageGo to next message
Dennis is currently offline  Dennis
Messages: 17
Registered: February 2004
Karma: 0
Junior Member
On Sun, 20 Mar 2011 13:14:29 -0400, Jerry Stuckle
<jstucklex(at)attglobal(dot)net> wrote:

> Can you post the actual code which is failing (or, if it's too long, a
> complete example of the failure)?

Here's a short sample that illustrates the problem...

<?php

foo();
echo "test done<br>";
exit;

function foo()
{
$doc = new DOMDocument();
$doc->formatOutput = true;

$title = $doc->createElement("title");
$doc->appendChild($title);

$title_data = "Some data followed by an ellipsesĀ…";

$title_text = $doc->createTextNode($title_data);
$title->appendChild($title_text);

$doc->saveXML();
$doc->save("test.xml");

echo "foo done<br>";
}

?>


--

Dennis
Re: Problem with appendChild and ellipsis... [message #173078 is a reply to message #173077] Sun, 20 March 2011 19:25 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/20/2011 2:24 PM, Dennis wrote:
> <?php
>
> foo();
> echo "test done<br>";
> exit;
>
> function foo()
> {
> $doc = new DOMDocument();
> $doc->formatOutput = true;
>
> $title = $doc->createElement("title");
> $doc->appendChild($title);
>
> $title_data = "Some data followed by an ellipsesā€¦";
>
> $title_text = $doc->createTextNode($title_data);
> $title->appendChild($title_text);
>
> $doc->saveXML();
> $doc->save("test.xml");
>
> echo "foo done<br>";
> }
>
> ?>

OK, running your code I get the following messages:

Warning: DOMDocument::saveXML(): string is not in UTF-8 in
C:\temp\domdoctest.php on line 20

Warning: DOMDocument::save(): string is not in UTF-8 in C:\temp
\domdoctest.php on line 21

Your problem is that the character you are using has no UTF-8
equivalent. You can't use characters not in the current charset.

Whenever I need ellipses I just use three periods (...).

BTW - if you had display_errors=on and error_reporting=E_ALL in your
php.ini file you would have seen these messages. I highly recommend
they be enabled on all development systems (but not production).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Problem with appendChild and ellipsis... [message #173079 is a reply to message #173078] Sun, 20 March 2011 19:56 Go to previous messageGo to next message
Dennis is currently offline  Dennis
Messages: 17
Registered: February 2004
Karma: 0
Junior Member
On Sun, 20 Mar 2011 15:25:21 -0400, Jerry Stuckle
<jstucklex(at)attglobal(dot)net> wrote:

> BTW - if you had display_errors=on

I thought I did, but I just looked again and it was off. It's on now.

> Whenever I need ellipses I just use three periods (...).

I do too. But the data I am extracting is from a WordPress table. For
some reason the WordPress page/post editor insists on changing three
periods to a single ellipsis. I haven't been able to figure out the
exact steps needed to get it to do this.

Thanks, everything is under control now.

--

Dennis
Re: Problem with appendChild and ellipsis... [message #173080 is a reply to message #173079] Sun, 20 March 2011 20:13 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/20/2011 3:56 PM, Dennis wrote:
> On Sun, 20 Mar 2011 15:25:21 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)net> wrote:
>
>> BTW - if you had display_errors=on
>
> I thought I did, but I just looked again and it was off. It's on now.
>

It's happened to me, also :)

>> Whenever I need ellipses I just use three periods (...).
>
> I do too. But the data I am extracting is from a WordPress table. For
> some reason the WordPress page/post editor insists on changing three
> periods to a single ellipsis. I haven't been able to figure out the
> exact steps needed to get it to do this.
>
> Thanks, everything is under control now.
>

OK, I would take that up with wordpress and see how to disable it -
either that or use a more appropriate charset (what does wordpress use?).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Problem with appendChild and ellipsis... [message #173082 is a reply to message #173080] Sun, 20 March 2011 20:51 Go to previous messageGo to next message
Dennis is currently offline  Dennis
Messages: 17
Registered: February 2004
Karma: 0
Junior Member
On Sun, 20 Mar 2011 16:13:45 -0400, Jerry Stuckle
<jstucklex(at)attglobal(dot)net> wrote:

> what does wordpress use?

They have this in wp-config.php:

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

Don't know if there might be other places where the charset is
specified.

--

Dennis
Re: Problem with appendChild and ellipsis... [message #173083 is a reply to message #173082] Sun, 20 March 2011 21:04 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/20/2011 4:51 PM, Dennis wrote:
> On Sun, 20 Mar 2011 16:13:45 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)net> wrote:
>
>> what does wordpress use?
>
> They have this in wp-config.php:
>
> /** Database Charset to use in creating database tables. */
> define('DB_CHARSET', 'utf8');
>
> Don't know if there might be other places where the charset is
> specified.
>

No idea - guess you're going to have to ask the wordpress people about it.

You could also look at the one of the pages and see what the charset
being used it. It might give you an idea.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Problem with appendChild and ellipsis... [message #173084 is a reply to message #173083] Sun, 20 March 2011 21:24 Go to previous messageGo to next message
Dennis is currently offline  Dennis
Messages: 17
Registered: February 2004
Karma: 0
Junior Member
On Sun, 20 Mar 2011 17:04:42 -0400, Jerry Stuckle
<jstucklex(at)attglobal(dot)net> wrote:

> No idea - guess you're going to have to ask the wordpress people about it.

Now that I know the problem, I can work around it. Although they do seem
to have a little inconsistency somewhere. When I see it happen again I
will try to document the steps that caused it and report it as a bug. If
I enter three periods then leave it as three periods.

> You could also look at the one of the pages and see what the charset
> being used it. It might give you an idea.

<meta charset="UTF-8" />

--

Dennis
Re: Problem with appendChild and ellipsis... [message #173085 is a reply to message #173084] Sun, 20 March 2011 21:42 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
Dennis wrote:

> Jerry Stuckle wrote:
>> You could also look at the one of the pages and see what the charset
>> being used it. It might give you an idea.
>
> <meta charset="UTF-8" />

That's in the <head> section? Better if you look at the page's actual
Response Headers, for something like this:

Content-Type: text/html; charset=utf-8

Firefox's Web Developer's Toolbar can give you the capability...

--
-bts
-Four wheels carry the body; two wheels move the soul
Re: Problem with appendChild and ellipsis... [message #173086 is a reply to message #173085] Sun, 20 March 2011 22:00 Go to previous messageGo to next message
Dennis is currently offline  Dennis
Messages: 17
Registered: February 2004
Karma: 0
Junior Member
On Sun, 20 Mar 2011 17:42:38 -0400, "Beauregard T. Shagnasty"
<a(dot)nony(dot)mous(at)example(dot)invalid> wrote:

>> <meta charset="UTF-8" />
>
> That's in the <head> section? Better if you look at the page's actual
> Response Headers, for something like this:
>
> Content-Type: text/html; charset=utf-8
>
> Firefox's Web Developer's Toolbar can give you the capability...

Content-Type: text/html; charset=UTF-8

--

Dennis
Re: Problem with appendChild and ellipsis... [message #173090 is a reply to message #173086] Sun, 20 March 2011 23:42 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
Dennis wrote:

> "Beauregard T. Shagnasty" wrote:
>> Dennis wrote:
>>> <meta charset="UTF-8" />
>>
>> That's in the <head> section? Better if you look at the page's
>> actual Response Headers, for something like this:
>>
>> Content-Type: text/html; charset=utf-8
>>
>> Firefox's Web Developer's Toolbar can give you the capability...
>
> Content-Type: text/html; charset=UTF-8

For kicks, try changing your page's head section to:
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

...then check again what the Response Headers say. Sometimes (often?) the
server overrules what the HTML says, at least in my experience...

--
-bts
-Four wheels carry the body; two wheels move the soul
Re: Problem with appendChild and ellipsis... [message #173093 is a reply to message #173090] Mon, 21 March 2011 00:16 Go to previous messageGo to next message
Dennis is currently offline  Dennis
Messages: 17
Registered: February 2004
Karma: 0
Junior Member
On Sun, 20 Mar 2011 19:42:04 -0400, "Beauregard T. Shagnasty"
<a(dot)nony(dot)mous(at)example(dot)invalid> wrote:

> Dennis wrote:
>
>> "Beauregard T. Shagnasty" wrote:
>>> Dennis wrote:
>>>> <meta charset="UTF-8" />
>>>
>>> That's in the <head> section? Better if you look at the page's
>>> actual Response Headers, for something like this:
>>>
>>> Content-Type: text/html; charset=utf-8
>>>
>>> Firefox's Web Developer's Toolbar can give you the capability...
>>
>> Content-Type: text/html; charset=UTF-8
>
> For kicks, try changing your page's head section to:
> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
>
> ..then check again what the Response Headers say. Sometimes (often?) the
> server overrules what the HTML says, at least in my experience...

Where is this leading? My problem was not having display_errors turned
on, which would have shown me that the string with the ellipsis was not
utf-8. I solved the latter problem by adding...

if (!mb_check_encoding($title_data, 'UTF-8'))
$title_data = mb_convert_encoding($title_data, 'UTF-8');

Now all is well.

--

Dennis
Re: Problem with appendChild and ellipsis... [message #173098 is a reply to message #173093] Mon, 21 March 2011 02:36 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
Dennis wrote:

> "Beauregard T. Shagnasty" wrote:
>> Dennis wrote:
>>> "Beauregard T. Shagnasty" wrote:
>>>> Dennis wrote:
>>>> > <meta charset="UTF-8" />
>>>>
>>>> That's in the <head> section? Better if you look at the page's
>>>> actual Response Headers, for something like this:
>>>>
>>>> Content-Type: text/html; charset=utf-8
>>>>
>>>> Firefox's Web Developer's Toolbar can give you the capability...
>>>
>>> Content-Type: text/html; charset=UTF-8
>>
>> For kicks, try changing your page's head section to:
>> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
>>
>> ..then check again what the Response Headers say. Sometimes (often?)
>> the server overrules what the HTML says, at least in my
>> experience...
>
> Where is this leading? My problem was not having display_errors
> turned on, which would have shown me that the string with the
> ellipsis was not utf-8. I solved the latter problem by adding...
>
> if (!mb_check_encoding($title_data, 'UTF-8'))
> $title_data = mb_convert_encoding($title_data, 'UTF-8');
>
> Now all is well.

It was a test to make sure your web server was or was not observing your
<meta> element. Just in case.

--
-bts
-Four wheels carry the body; two wheels move the soul
Re: Problem with appendChild and ellipsis... [message #173099 is a reply to message #173077] Mon, 21 March 2011 08:26 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 20/03/2011 19:24, Dennis escribiĆ³/wrote:
> On Sun, 20 Mar 2011 13:14:29 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)net> wrote:
>
>> Can you post the actual code which is failing (or, if it's too long, a
>> complete example of the failure)?
>
> Here's a short sample that illustrates the problem...
>
> <?php
>
> foo();
> echo "test done<br>";
> exit;
>
> function foo()
> {
> $doc = new DOMDocument();
> $doc->formatOutput = true;
>
> $title = $doc->createElement("title");
> $doc->appendChild($title);
>
> $title_data = "Some data followed by an ellipsesā€¦";
>
> $title_text = $doc->createTextNode($title_data);
> $title->appendChild($title_text);
>
> $doc->saveXML();
> $doc->save("test.xml");
>
> echo "foo done<br>";
> }
>
> ?>

If I run this code I get this file:

<?xml version="1.0"?>
<title>Some data followed by an ellipses&#x2026;</title>

.... where &#x2026; is the entity for ellipsis.

My guess is that you are feeding createTextNode() with the wrong encoding:

http://es2.php.net/manual/en/intro.dom.php

Ā«The DOM extension uses UTF-8 encoding. Use utf8_encode() and
utf8_decode() to work with texts in ISO-8859-1 encoding or Iconv for
other encodings. Ā»



--
-- http://alvaro.es - Ɓlvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programaciĆ³n web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Problem with appendChild and ellipsis... [message #173101 is a reply to message #173079] Mon, 21 March 2011 08:53 Go to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Dennis)

> On Sun, 20 Mar 2011 15:25:21 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)net> wrote:
>
>> BTW - if you had display_errors=on
>
> I thought I did, but I just looked again and it was off. It's on now.
>
>> Whenever I need ellipses I just use three periods (...).
>
> I do too.

For good typography you should use the correct characters. A " for
example is not a quote sign and ... are just three dots, but not an
ellipsis. But with Unicode you can use all the correct chars instead
of just their ugly ASCII replacements, like ā€žā€œ and ā€¦ for example.

> But the data I am extracting is from a WordPress table. For
> some reason the WordPress page/post editor insists on changing three
> periods to a single ellipsis.

Which is usually correct and recommended. You just have an encoding
problem somewhere. And if you don't fix it, it might also happen with
other special chars.

Micha
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: PHP Module Writing Help
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 22:52:21 GMT 2024

Total time taken to generate the page: 0.02842 seconds