Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/168940-echo-with-variables/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/168940-echo-with-variables/#findComment-891359
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/168940-echo-with-variables/#findComment-891411
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.