The eval () function of PHP

Source: Internet
Author: User

The eval () function calculates the string according to the PHP code.

Usage: eval (phpcode);


Case 1:

$a = ' name '; $b = ' my '; $d = ' $b $a is Helen '; Echo $d. " <br/> eval ("\ $d = \" $d \ ";"); echo $d. " <br/> ";

Output Result:

$b $a is helenmy name is Helen

Case 2:

Application scenario: Determine if the data passed by Ajax is an array format

$var config_value = $ (' #config_value '). Val ();//This is a configuration item that is similar to the array (all-in-one) arrays format $.ajax ({type: "POST", url : "ajax/checkarray.php", Data: "Config_value=" +config_value, Async:false, Success:functio                N (data) {alert (data); }         });

checkarray.php page

$config _value = $_post[config_value ']; $str 1 = $nns _config_item_value;eval ("\ $str 1 = $str 1;"); if (!is_array ($str 1)) {echo ' Config item value failed validation, not array or array format is incorrect! ";}



The eval () function of PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.