horobey Posted November 29, 2003 Share Posted November 29, 2003 I am coding PHP extension. I need to execute PHP code from withing C function in this extesion. PHP code is stored in the string like char * str = \"<?PHP echo(\'test\'); ?>\"; now if I call zend_eval_string() it complains about <?PHP ?> tags. I would like the same functionality like zend_eval_string() but with possibility to pass whole PHP file to contained in the string. Any ideas? yuriy@horobey.com PS really tired looking to solve this... Quote Link to comment Share on other sites More sharing options...
Derek Posted December 3, 2003 Share Posted December 3, 2003 I\'m guessing its safe to assume you tried it without the <?PHP ?> tags...? Quote Link to comment Share on other sites More sharing options...
horobey Posted December 3, 2003 Author Share Posted December 3, 2003 yes, I\'ve tried. without <?PHP ?> it works fine Quote Link to comment Share on other sites More sharing options...
Derek Posted December 3, 2003 Share Posted December 3, 2003 well then, therein lies your answer. Remove any <?PHP and ?> from input, then use the function. Quote Link to comment Share on other sites More sharing options...
horobey Posted December 3, 2003 Author Share Posted December 3, 2003 i would like it to be parsed by stanfard zend engine Quote Link to comment Share on other sites More sharing options...
Derek Posted December 3, 2003 Share Posted December 3, 2003 er, I don\'t really understand what you\'re getting at. Be more concrete, I don\'t see a problem with removing <?PHP and ?> internally. Quote Link to comment Share on other sites More sharing options...
horobey Posted December 3, 2003 Author Share Posted December 3, 2003 <?PHP echo("PHP block 1<br>"); ?> this is not PHP<br> <% echo("php block 2<br>"); $v="this is not end %>"; %> this is not PHP<br> <script language="PHP"> $v=<<<EV <?PHP this is not PHP block ?> EV; </script> <? echo("<?PHP this is not PHP block?>"); ?> I think you can continue this sample. I mean it is difficult to split PHP file into valid PHP blocks I think I need to study Zend code... Quote Link to comment Share on other sites More sharing options...
Derek Posted December 3, 2003 Share Posted December 3, 2003 no, that\'s pretty easy with a simple regex. But...I don\'t know what your extension is for, but if its just for you, a warning, don\'t use shorttags, script tags, or asp tags; most servers don\'t have them enabled. stick to <?php ?>. Quote Link to comment Share on other sites More sharing options...
horobey Posted December 3, 2003 Author Share Posted December 3, 2003 i should be able to process all valid PHP files. my extension is something to process PHP before executing and if everything is OK then just execute the code. Quote Link to comment Share on other sites More sharing options...
daeken Posted December 4, 2003 Share Posted December 4, 2003 If you\'re processing the code, you should have absolutely no problem identifying code blocks... if you can\'t do that, then you really need to think about the way your processor works. Quote Link to comment Share on other sites More sharing options...
horobey Posted December 4, 2003 Author Share Posted December 4, 2003 my procwssor is in very early stage. Right now forget it. Just lets concentrated on how to make Zend parse and execute the PHP file contained in the string? Quote Link to comment Share on other sites More sharing options...
Derek Posted December 5, 2003 Share Posted December 5, 2003 If the zend_eval_string function (which you want to use, im assuming its what does the work in zend, but I havn\'t looked and am at school now and cannot) (and which im hoping isn\'t like using eval(), heh ) doesn\'t like opening and closing tags, then you have to remove them. Separate your blocks, strip the tags, then feed them to zend_eval_string separatly. I havn\'t really looked at zend much, but daeken has. I don\'t really get what you mean by \"parse and execute the PHP file contained in the string\", but I\'m assuming you just want your extension to open and parse PHP from files...in which case im wondering why you\'re making the extension at all... Quote Link to comment Share on other sites More sharing options...
Amaranth Posted January 3, 2004 Share Posted January 3, 2004 In PHP when using eval() you can fix this problem by prepending a ?> to the string like so: eval('?>' . $code); Have you tried something like this? Quote Link to comment Share on other sites More sharing options...
daeken Posted January 3, 2004 Share Posted January 3, 2004 wow, i never knew about that. thanks amaranth Quote Link to comment Share on other sites More sharing options...
cyberjupie Posted June 18, 2008 Share Posted June 18, 2008 may be horobey want to encrypt some PHP string code, decrypt inside the extension and executing there, right, horobey ? If it is so, his problem is same as me. I want to evaluate php string within an extension, i use zend_eval_string(), success for simple php code like: $str = "print \"hello, world!\";"; but, display error when zend_eval_string() parse some php code like: $str = "function {print \"hello, world!\";}"; Any solution for this? Please, help. If the zend_eval_string function (which you want to use, im assuming its what does the work in zend, but I havn\'t looked and am at school now and cannot) (and which im hoping isn\'t like using eval(), heh ) doesn\'t like opening and closing tags, then you have to remove them. Separate your blocks, strip the tags, then feed them to zend_eval_string separatly. I havn\'t really looked at zend much, but daeken has. I don\'t really get what you mean by \"parse and execute the PHP file contained in the string\", but I\'m assuming you just want your extension to open and parse PHP from files...in which case im wondering why you\'re making the extension at all... Quote Link to comment Share on other sites More sharing options...
Smystery Posted October 21, 2008 Share Posted October 21, 2008 I have same problem, Any solution ??? Quote Link to comment Share on other sites More sharing options...
o3d Posted October 24, 2008 Share Posted October 24, 2008 char *cBuffer; cBuffer = (char*)malloc(2048); memset(cBuffer, 0x00, 2048); strcpy(cBuffer, "echo 'this is some php text';"); //execute decrypted php code via ZEND engine zend_try { zend_eval_string(cBuffer, NULL, "PHP Script"); free(cBuffer); } zend_catch { free(cBuffer); php_error(E_ERROR, "Error occurred while executing PHP code, ERR - 101\0"); RETURN_BOOL(0); } zend_end_try(); You could try this Quote Link to comment 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.