milou Posted August 5, 2009 Share Posted August 5, 2009 I've a quite simple question: I've a txt file with possibly some php variables (the file is filled by a form: before printing it in the file I apply $text= trim(mysql_escape_string(strip_tags($_POST['someField']))); ) . I read the file and save it in variables (using explode). Before I print these variables I apply $tekst = "".stripcslashes(htmlspecialchars_decode("".$text[0])); $text only contains one element. Sadly, the variables are not recognized as variables but are only printed as their name. For example this works fine, $me is one of those variables, I use double quotes "..": $personal_data=array(); $personal_data['first name'] = "Me $me again"; echo $personal_data['first name']; //$me is printed as its value This does not work (text[0] contains the $me variable) echo $text[0]; it prints $me as it variable name, not as its value echo "$me".$text[0]; Here the first $me value is printed fine, again $text[0] prints $me by its name The var_dump of $text[0] is string(11) "Testing $me" Somebody knows the solution? Quote Link to comment https://forums.phpfreaks.com/topic/168940-echo-with-variables/ Share on other sites More sharing options...
wildteen88 Posted August 5, 2009 Share Posted August 5, 2009 Is the variable $me coming from the value of a form field? It if its PHP wont parse variables within forms. It will treat them as normal text. To parse these variables you'll have to use eval. However this can be very dangerous. Can you explain more clearly what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/168940-echo-with-variables/#findComment-891359 Share on other sites More sharing options...
milou Posted August 5, 2009 Author Share Posted August 5, 2009 Off course. I have a form, applying the above method I save the input textsfields in a file. I read this file later, there I apply the other above method. Then I try to print the text, where sadly these texts are printed as variablesnames iso variablesvalues. Why is eval() dangerous? in the file, $me is nicely printed as variablename. Only when printing, the variable will have a value. Quote Link to comment https://forums.phpfreaks.com/topic/168940-echo-with-variables/#findComment-891411 Share on other sites More sharing options...
wildteen88 Posted August 5, 2009 Share Posted August 5, 2009 PHP will not parse variables from files that are being read either. Quote Link to comment https://forums.phpfreaks.com/topic/168940-echo-with-variables/#findComment-891448 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.