• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

PHP eval with img src

Hi Experts!

I´m looking for a way to render objects from database like this:

<?php
$v = '<img src="teste.png" />';
eval($v);
?>

but it doesn't works fine.

Any idea?

Thanks in advance.
0
ZumbaJr
Asked:
ZumbaJr
  • 3
1 Solution
 
zicevaCommented:
Is this what you want?

<?php
$v = '<img src="teste.png" />';
echo $v;
?>
0
 
DerokorianCommented:
eval() runs the string passed to it as php code. Instead it looks like you should be using echo()

<?php
$v = '<img src="teste.png" />';
echo $v;
?>

Open in new window

0
 
ZumbaJrAuthor Commented:
I´m sorry!

I have some code php into database var like this:

<?php
$v = '<img src="<?php echo $rootfolder; ?>/teste.png" />';

???

?>

0
 
zicevaCommented:
http://php.net/manual/en/function.eval.php

The code string to be evaluated. code_str does not have to contain PHP Opening tags.
0
 
zicevaCommented:
And as an advice, you should really avoid this course of action ... eval() is REALLY slow, and storing code in the database is a real NO NO for security ...

If the only thing you store in the database are variables, you could use some hashes and replace them on runtime like this:

<?php
$v = '<img src="ROOT_FOLDER/teste.png" />';

$v=str_replace(array ('ROOT_FOLDER','OTHER_HASH','ANOTHER_HASH'),array($rootfolder,$othervalue,$anothervalue),$v);

echo $v;
?>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now