You are here: Re: [PHP] eval(); « PHP « IT news, forums, messages
Re: [PHP] eval();

Posted by Jasper Bryant-Greene on 10/31/05 04:35

On Sun, 2005-10-30 at 21:24 -0500, John Taylor-Johnston wrote:
> <?php
>
> >>$contents = "<div class=\"indent\" style=\"font-size: 16px; font-family:
> >>arial,helvetica; font-weight: bold;\">About the Project</div>
> >><?php echo \"hello world\"; ?>";
> >>echo eval($contents);
> >>?>
> >>eval() expects PHP code, not HTML with embedded PHP code. Try this
> >>(untested):
> >>
> >>eval( " ?> $contents <?php " );
> >>
> Scary. But it works.
> Shouldn't that error because of the unexpected ?> and <?php in a bigger
> example?

No, because eval(), when passed string $str, effectively does this
silently:

$str = "<?php " . $str . " ?>";

and then passes $str to the PHP interpreter.

Which is, in most cases, what you want, because you want to evaluate PHP
code.

However, if eval() is the answer, you're probably asking the wrong
question. You should take a hard look at your code and think of a better
way to do what you need to do.

I can assure you one does exist, but with your example it's fairly
obvious, so you'd need to explain better what you're trying to do before
I could help you.

--
Jasper Bryant-Greene
General Manager
Album Limited

e: jasper@album.co.nz
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация