Xu Wei Jie Posted March 4, 2009 Share Posted March 4, 2009 Hi all, I am working on how to manipulate PHP tokens to parse certain tags (http://sg2.php.net/tokens) Anyone has any idea on how to map a symbol like "<?+" to T_OPEN_TAG instead of the usual"<?php" ? TIA Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/ Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 firstly, I remember you, and you are completely getting the wrong concept of these 'token's they are not for USE in a script they are used in DEBUGGING scripts, E.G. "Unexpected T_OPEN_TAG in whateverphpfile.php at line 17" You're looking to output php snippets inside of php, now I have recommended you use nowdoc or heredoc echoing, but you think adding the extra 2 lines is an inconvenience and makes it look 'sloppy' well, there is no other way, you NEED to echo to output, or not echo at all and close the php tag, and type out the actual code.. e.g. <?php yadayada ?><php echo "hey!"; ?><?php yadayadayada ?> I have just looked at the link I supplied, and noticed that nowdoc apparently only works in 5.2.9 which I don't quite understand, coz otherwise I really wouldn't know about it unless I looked it up b4 and don't remember.. but heredoc will 'course render any variables and such.. so thats not that great, guess you're stuck echoing it manually or go with a database and just select it out as text by default, then echoing text is not that hard Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-776455 Share on other sites More sharing options...
PFMaBiSmAd Posted March 4, 2009 Share Posted March 4, 2009 You have never provided information about the overall goal you are trying to accomplish, only generic bits and pieces about what you are trying to do at a particular point, so you have never gotten a real good answer on how to do it. I suspect you should be looking at a template system - http://www.smarty.net/ Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-776457 Share on other sites More sharing options...
Xu Wei Jie Posted March 4, 2009 Author Share Posted March 4, 2009 Is there really no alternative? I really hate to output to echo or NOWDOC. I do know the concept of tokens and I understand it is not to be manipulated just any way. However, I wish to do some experimentation so I can get the PHP interpreter to interpret the scripts according to how I want it to work. All in the name of experimentation and trial error. In the case no one know what I wish to achieve, let me make it more clearer i.e. <?php echo <?+ echo "Yeah I got this echoed" +?> ?> I wish to tell the interpreter to interpret whatever is within <?+ +?> and not within <?php ?>. Thus I need to manipulate T_OPEN_TAG to bypass <?php tags or if needed to override the token for '?>' I apologise because the topic back then I posted was quite old (about 5-6 pages back )and I did not get it solved thus I wish to rephrase what I want to achieve. =) Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-776461 Share on other sites More sharing options...
RussellReal Posted March 4, 2009 Share Posted March 4, 2009 well bro, you can't =\ I don't think atleast.. but I'll rephrase your question in this post and maybe a guru will be some help to you.. my friend here wants to know how, if possible, he could sort of 'create' a php tag, which automatically outputs the containing block of code, rather than evaluating it.. for example he'd have <?php+ echo "hey!": $abc = 123; echo max((ceil($abc * $abc) / .5),1); ?> and he'd want that block of code to RETURN or OUTPUT <?php echo "hey!": $abc = 123; echo max((ceil($abc * $abc) / .5),1); ?> to the command line and or web browser.. Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-776467 Share on other sites More sharing options...
Xu Wei Jie Posted March 5, 2009 Author Share Posted March 5, 2009 Any php gurus to help out? ^.^ Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-777125 Share on other sites More sharing options...
Xu Wei Jie Posted March 6, 2009 Author Share Posted March 6, 2009 .................... Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-777851 Share on other sites More sharing options...
corbin Posted March 6, 2009 Share Posted March 6, 2009 You would have to modify the core PHP code. Have fun. Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-777855 Share on other sites More sharing options...
vicodin Posted March 6, 2009 Share Posted March 6, 2009 I just don't get why you are trying to reinvent the wheel? Whats the point? Your gonna end up with the same result in the end? Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-777863 Share on other sites More sharing options...
Xu Wei Jie Posted March 6, 2009 Author Share Posted March 6, 2009 Corbin, do you know which part of the core PHP code do I have to edit the T_OPEN_TAG? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-777881 Share on other sites More sharing options...
Xu Wei Jie Posted March 6, 2009 Author Share Posted March 6, 2009 I just don't get why you are trying to reinvent the wheel? Whats the point? Your gonna end up with the same result in the end? Actually I am not trying to reinvent the wheel. I am just doing some experimentation though it may not be a practical solution. At the same time, I can also understand how php parsing works. Thus, I need some help on where in the php core files can I edit the T_OPEN_TAG to '<?+' for example. Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-778036 Share on other sites More sharing options...
Xu Wei Jie Posted March 7, 2009 Author Share Posted March 7, 2009 I have found a solution. Preprocessing (by inter switching) the tags before running CLI and do post processing of the tags =) Quote Link to comment https://forums.phpfreaks.com/topic/147939-solved-php-tokens/#findComment-779187 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.