Hawkar Oghiz
Hawkar Oghiz

Reputation: 35

eval()'d code on line xx

i have this code , i want to convert the get(title) to variable , its correctly working , for example i have variable 'news , sport, program ' , my problem is that when someone is changing the title="news" to title=new , and i dont have the new variable how i can control it when the user change the title ; this will appear an error that the variable undefined and eval()'d code on line xx error

if(isset($_GET['title']))
    $title=stripslashes($_GET['title']);
else
   $title="news";

$trimed=trim(strtolower($title));
$variable="$".str_replace(" ","_",$trimed);
$title=eval('return '.$variable.';');  

if(!isset($title))
    $title=$$title;

thank you for help

Upvotes: 3

Views: 33711

Answers (2)

dynamic
dynamic

Reputation: 48101

Just do like this:

$nameOfVar = 'return' . $variable;
$title = $nameOfVar;

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382696

You can use ${} syntax and replace:

$title = eval('return '. $variable.';');  

With:

$title = ${'return '. $variable};  

Upvotes: 1

Related Questions