Nestor A Diaz | 1 Feb 19:10

Escape PHP tags '<? ?>' on HTML Comments <!-- //-->

Hello, i am not sure if this is the supposed behaviour, but suppose i have the following code inside a template.

<!--
<?xml version="1.0" encoding="utf-8"?>
//-->

It will render as is, so having a problem regarding the generated PHP code because the <? ?>

Parse error: syntax error, unexpected T_STRING in ...

but since tal expessions are *not* evaluated inside comments i can't process it with a tal expression.

Shouldn't be the right behaviour to escape such characters when they are inside an html comment ?

I was thinking on implementing something like this on phptal for such case:

echo <<<uuid
<!--
<? blah blah ?>
//-->
uuid;

Waiting for comments ...

Slds.

-- Nestor A. Diaz Ingeniero de Sistemas Tel. +57 1-485-3020 x 211 Cel. +57 316-227-3593 Tel. SIP: sip:211-NS/jz+eG3AXzfdHfmsDf5w@public.gmane.org Email/MSN: nestor-NS/jz+eG3AXzfdHfmsDf5w@public.gmane.org http://www.tiendalinux.com/ Bogota, Colombia
_______________________________________________
PHPTAL mailing list
PHPTAL@...
http://lists.motion-twin.com/mailman/listinfo/phptal
Kornel Lesiński | 1 Feb 22:46
Gravatar

Re: Escape PHP tags '<? ?>' on HTML Comments <!-- //-->

On Wed, 01 Feb 2012 18:10:30 -0000, Nestor A Diaz <nestor@...>  
wrote:

> Hello, i am not sure if this is the supposed behaviour, but suppose i
> have the following code inside a template.
>
> <!--
> <?xml version="1.0" encoding="utf-8"?>
> //-->
>
> It will render as is, so having a problem regarding the generated PHP
> code because the <? ?>
>
> *Parse error*: syntax error, unexpected T_STRING in ...

PHPTAL allows PHP blocks in comments too (perhaps it shouldn't...) and you  
have short_open_tag enabled in php.ini, which makes all <? ?> blocks, even  
<?xml ?> interpreted as PHP code.

If you're not using <? blocks for PHP code (and always use <?php ) then  
you can disable short_open_tag setting.

Otherwise you need to change <?xml to something else or output it using  
<?php echo '<?xml'; ?>

--

-- 
regards, Kornel Lesiński
Nestor A Diaz | 2 Feb 15:29

Re: Escape PHP tags '<? ?>' on HTML Comments <!-- //-->

ok, i will follow your recommendation and not use php short tags 
anymore, is it the recommended way from php developers too.

slds.

-- 
Nestor A. Diaz
Ingeniero de Sistemas
Tel. +57 1-485-3020 x 211
Cel. +57 316-227-3593
Tel. SIP: sip:211@...
Email/MSN: nestor@...
http://www.tiendalinux.com/
Bogota, Colombia

On 02/01/2012 04:46 PM, Kornel Lesiński wrote:
> On Wed, 01 Feb 2012 18:10:30 -0000, Nestor A Diaz 
> <nestor@...> wrote:
>
>> Hello, i am not sure if this is the supposed behaviour, but suppose i
>> have the following code inside a template.
>>
>> <!--
>> <?xml version="1.0" encoding="utf-8"?>
>> //-->
>>
>> It will render as is, so having a problem regarding the generated PHP
>> code because the <? ?>
>>
>> *Parse error*: syntax error, unexpected T_STRING in ...
>
> PHPTAL allows PHP blocks in comments too (perhaps it shouldn't...) and 
> you have short_open_tag enabled in php.ini, which makes all <? ?> 
> blocks, even <?xml ?> interpreted as PHP code.
>
> If you're not using <? blocks for PHP code (and always use <?php ) 
> then you can disable short_open_tag setting.
>
> Otherwise you need to change <?xml to something else or output it 
> using <?php echo '<?xml'; ?>
>

Gmane