Evaluating Strings In PHP

0
Your rating: None

In PHP the function eval() will evaluate a string as a PHP code.

For example,

eval ( "echo 'Hello Name';" );

in the above code eval will take the contents of the string and execute it and hence will produce the same output as

echo 'Hello Name';

There may be lot of cases when eval() can be useful. You can store blocks of code in a database, and retrieve and eval() them at a later point. You can generate code in a loop, and then use eval() to execute it. You can safely use eval() to update or correct existing code.

If you had a large collection of scripts that needed a predictable change, it would be possible (but inefficient) to write a script that loads an old script into a string, runs a regexp to make changes, and then uses eval() to execute the modified script.

It is even conceivable that a very trusting person somewhere might want to allow PHP code to be entered in a browser and executed on her server.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India