PHP 根据前台传递的字符计算值,该怎么处理

WBOY
Release: 2016-06-13 13:30:09
Original
961 people have browsed it

PHP 根据前台传递的字符计算值
前台:


后台:

$b=1; $c=2;
$a = $b.$_POST['a'].$c;

如果选择的是第一个 =

则会出现语法错误。

请问有什么方法使其正确,$a=2

------解决方案--------------------
你可以在后台来判断$_POST['a']的值,如果是=,你采取$a=$c;

------解决方案--------------------
用switch来挨个的比较,不能像你这么简单地$a = $b.$_POST['a'].$c;处理。

------解决方案--------------------
不大可能出现语法错误。
------解决方案--------------------
楼主这样得用eval了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template