Xu Wei Jie Posted February 27, 2009 Share Posted February 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/ Share on other sites More sharing options...
RussellReal Posted February 27, 2009 Share Posted February 27, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772444 Share on other sites More sharing options...
Xu Wei Jie Posted February 27, 2009 Author Share Posted February 27, 2009 That will be kinda messy. what if I just want to parse inline tags as plain text? How do I tell the interpreter which tags to parse and which tags not to? Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772451 Share on other sites More sharing options...
RussellReal Posted February 27, 2009 Share Posted February 27, 2009 use < instead of < and use > instead of > <pre><php ... ... .. .. ?></pre> Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772523 Share on other sites More sharing options...
Xu Wei Jie Posted February 27, 2009 Author Share Posted February 27, 2009 I forgot to mention. It goes through a PHP interpreter and not a server thus HTML tags would not be interpreted as well. I am trying to ask the PHP CLI not to interpret certain php tags. Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772538 Share on other sites More sharing options...
RussellReal Posted February 27, 2009 Share Posted February 27, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772560 Share on other sites More sharing options...
Xu Wei Jie Posted February 27, 2009 Author Share Posted February 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772567 Share on other sites More sharing options...
RussellReal Posted February 27, 2009 Share Posted February 27, 2009 you could still do echo <<<'LaLa' <?php echo "test";?> LaLa; Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772634 Share on other sites More sharing options...
Xu Wei Jie Posted February 27, 2009 Author Share Posted February 27, 2009 yah but a one liner becomes a 3 liner in nowdoc syntax Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772658 Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 its either that or manually escape things lol Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-772961 Share on other sites More sharing options...
Xu Wei Jie Posted February 28, 2009 Author Share Posted February 28, 2009 Yup, that is why I am looking into php parsed tokens (http://sg2.php.net/tokens) to see how it can be done. Anyone have experience with using these tokens to interpret php tags? Would appreciate if you could share with me ^.^ Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-773158 Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2009 Share Posted February 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-773264 Share on other sites More sharing options...
Xu Wei Jie Posted February 28, 2009 Author Share Posted February 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-773326 Share on other sites More sharing options...
Xu Wei Jie Posted March 3, 2009 Author Share Posted March 3, 2009 Anyone have any idea to this problem? Quote Link to comment https://forums.phpfreaks.com/topic/147137-solved-escaping-for-php-tags/#findComment-775244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.