0

EDIT: This question has been edited from the original

I have a string in a database with HTML and PHP variable's inside. Some of the HTML has double quotes as if I try to use single quotes the database escapes it by adding a quote in front of it like so: ' '.

I want to query the string and assign it to variable $x. And then use eval("\$x = \"$x\";"); to parse the PHP variable, but it seems the double quote is ruining the eval(), and the variables are not parsing.

Is there a way to allow PHP to read the variable?

I am aware, but anyone reading this should also be aware that using eval() can be very dangerous!

Any help would be greatly appreciated!

Dan W.
  • 107
  • 6
  • You can achieve it using `str_replace` if you only want to replace certain values. – Spoody May 22 '18 at 22:04
  • @quentin I edited the question with the reason that solution did not work, it is no longer a duplicate. – Dan W. May 23 '18 at 21:05

1 Answers1

0

If your SQL string looks like this: myVar then php:

$myVar = 'hello!';
echo $$var;

If your SQL string looks like this: 3 + 5 then php:

eval($var);

In first option we use Variable Variables

In second option we use eval to evaluate code in string.

Justinas
  • 41,402
  • 5
  • 66
  • 96