Jump to content

Recommended Posts

I read about this link ( http://sg2.php.net/tokens ) on how the parser treats php open and close tags as tokens.

 

Previously, I asked about how to parse php tags as plain text and I was given solutions like using single quotes or the NOWDOC syntax.

 

i.e <?php echo '<?php echo "this is just plain text"?>' ?>

 

and

 

<?php

> echo <<<'EOD'

> <?php echo "this is just plain text" ?>

> EOD;

> ?>

 

I was wondering if there are any other solutions to escape php tags. Thanks everyone

 

 

Link to comment
https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/
Share on other sites

1.. you could basically read whatever file you want..

 

like

 

if you want to show the code to lets say.. dothat.php

 

you could just do

 

<?php

$f = fopen($file = "dothat.php",'r');

$text = fread($f,filesize($file));

fclose($f);

echo htmlEntities($f);

?>

you mean say you have a file

 

whatever.php

 

and you call it like

 

php whatever.php

 

you want it to READ out to you the contents of whatever.php

 

or do you want in the middle of some script,. to spit out some php code..?

 

assuming its the second one..

 

nowdoc would make the most sense

 

e.g

 

echo <<<'LaLa'

<?php

$e = "HOWDY!!";

echo $e;

?>

LaLa;

I also think that nowdoc is very sleek. However, if I want it to be a single liner i.e. <?php echo "test"> to be processed as plain text

 

The one that makes the most sense is <?php echo '<?php echo "test">'?>

 

nowdoc just makes the code a multi line code. It will make it hard to read.

 

Thus, I was wondering if I can tell the CLI not to interpret certain tags other than the solutions as typed above.

 

I have extra information about the tags being interpreted as tokens (http://sg2.php.net/tokens)

It states that <?php is interpreted as T_OPEN_TAG by the php cli. However , I don't know how to use it to my advantage.

The tokens (T_OPEN_TAG...) only exist after the code has been parsed and is in the intermediate "bytecode" form, before the interpretation/execution phase. Since you appear to be doing something with the php source code, anything at the point where the code is in the form of tokens won't help because all the code will be in the form of tokens.

 

If you state the overall goal of what you are trying to accomplish, someone can probably provide a direct answer on how to do it.

 

Edit: And did you ever look at the highlight_string function that was posted in your other thread on this subject - http://www.phpfreaks.com/forums/index.php/topic,238908.msg1113516.html#msg1113516

Yes I did take a look at the highlight function but it returns you additional html tags as well which is not what I wanted.

 

What I wish to accomplish can be as simple as

 

<?php echo '<?php echo 'This is a tag within a tag'?>'?> but I wish to find a more elegant solution. Because the above solution or the nowdoc syntax makes code hard to read. I would like to tell the parser to interpret certain php tags and escape certain php tags.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.