[phplib] Re: odd behaviour when parse()-ing a block From: Dima Nemchenko (Dima.Nemchenko <email protected>)
Date: 06/05/01

Dima Nemchenko wrote:

> Dima Nemchenko wrote:
>
>> Hi all,
>>
>>
>> I wonder if anyone has had this same problem and, if so, could
>> explain it to me. I'm using PHP Version 4.0.5 and PHPLib 7.2b,
>> though I've modified template.inc:
>>
>> diff -uNr ~/template.inc ~/php/template.inc
>> --- /home/myhomepageonline/template.inc Mon Jun 4
>> 14:04:33 2001
>> +++ /home/myhomepageonline/php/template.inc Mon Jun 4
>> 14:02:43 2001
>> @@ -106,7 +106,10 @@
>> $str = $this->get_var($parent);
>> $reg = "/<!--\s+BEGIN $handle\s+-->(.*)<!--\s+END
>> $handle\s+-->/sm";
>> preg_match_all($reg, $str, $m);
>> - $str = preg_replace($reg, "{$name}", $str);
>> +# $str = preg_replace($reg, "{$name}", $str);
>> +# 2001-05-30, dn <email protected>
>> +# q.v.
>> http://www.phpbuilder.com/mail/phplib-list/2000071/0108.php
>>
>> + $str = preg_replace($reg, "{"."$name}", $str);
>> $this->set_var($handle, $m[1][0]);
>> $this->set_var($parent, $str);
>> }
>>
>>
>> I've got a block in the main template, which is parsed twice, with
>> two different templates substituted for the block item. Everything
>> works ok, but...
>>
>> Looking at the source, I see that all the HTML "entities" from the
>> second template, like "&lt;" and "&nbspl", have been translated into
>> "plain" ASCII characters, like "<" and " ". This doesn't happen in
>> the first template, or if I parse without appending.
>>
>> Has anyone else seen this?
>>
>>
>>
>> Thanks in advance for all your time,
>> --
>>
>> :D_ima
>
> Hello all,
>
>
> I've managed to narrow this down somewhat. I've also upgraded to
> PHPLib 7.2c
>
> The problem occurs because one of the templates has JavaScript code.
> There are calls to 'document.write()', and these seem to cause PHPLib
> to parse the "&lt;"s and others into ASCII.
>
> What is the recommended way to embed JavaScript in Templates?
>
>
> Thanks,
> --
>
> :D_ima

Oh dear...

I think this isn't a PHPLib issue at all, but rather a bug in Netscape
Navigator 4.77. Using telnet to GET the page work ok, as does IE.

It's pretty bizarre that this would happen, since a Template
parse-without-append works in Netscape, too.

Anyway, thank you, Maxim and Lazaro, for your suggestions.

--

:D_ima Dima Nemchenko <Dima.Nemchenko <email protected>>

"Open source code is like lobster--most people who haven't tried it don't like the way it looks. But those who try it, love it."