nivas_kumar Posted March 17, 2009 Share Posted March 17, 2009 hi.. I need to assign php code to string variable but it display errors please help me. Code: $stringdata="<?php $str = &$str[$blocks[$i]]; $str = &$str[sizeof($str) - 1]; ?>"; Link to comment https://forums.phpfreaks.com/topic/149772-how-i-assign-php-code-to-variable/ Share on other sites More sharing options...
trq Posted March 17, 2009 Share Posted March 17, 2009 What errors? Link to comment https://forums.phpfreaks.com/topic/149772-how-i-assign-php-code-to-variable/#findComment-786475 Share on other sites More sharing options...
Floydian Posted March 17, 2009 Share Posted March 17, 2009 The easiest way to do something like this, is to import the text into the script. Otherwise, you'll just have to manually escape anything that needs escaping. Luckily for you though, in this case, you can simply use single quotes and the string you have there will be saved to the variable just fine. Just in case you're planning on using that string in an eval(), remember the wise words of the creator of PHP Rasmus Leardorf: "If the answer to your question is using eval(), then you almost certainly did not ask the right question."; Link to comment https://forums.phpfreaks.com/topic/149772-how-i-assign-php-code-to-variable/#findComment-786476 Share on other sites More sharing options...
nivas_kumar Posted March 17, 2009 Author Share Posted March 17, 2009 Error is: Parse error: syntax error, unexpected '[', expecting ']' in C:\xampp\htdocs\zpro.php on line 3 And Code is: File Name:zpro.php echo $stringdata="<?php $str = &$str[$blocks[$i]]; $str = &$str[sizeof($str) - 1]; ?>"; after $stringdata, It will be stored in new file. Link to comment https://forums.phpfreaks.com/topic/149772-how-i-assign-php-code-to-variable/#findComment-786482 Share on other sites More sharing options...
Floydian Posted March 17, 2009 Share Posted March 17, 2009 Did you try using single quotes? after $stringdata, It will be stored in new file. If that was a response to -- import the text into the script I think you missed my point there. What I said is about where you get the string from, you're talking about where it goes when you're done. Link to comment https://forums.phpfreaks.com/topic/149772-how-i-assign-php-code-to-variable/#findComment-786489 Share on other sites More sharing options...
nivas_kumar Posted March 17, 2009 Author Share Posted March 17, 2009 Fine. I changed single quotes, now working . Thanks for proper explanation and thanks phpfreaks for the opportunity thank you Floydian. Link to comment https://forums.phpfreaks.com/topic/149772-how-i-assign-php-code-to-variable/#findComment-786499 Share on other sites More sharing options...
Floydian Posted March 17, 2009 Share Posted March 17, 2009 You're welcome Link to comment https://forums.phpfreaks.com/topic/149772-how-i-assign-php-code-to-variable/#findComment-786504 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.