本文目录一览:
怎么用php编写加减乘除??
可以参考下面的代码:
?php
$a = 1;
$b = 2;
加法: $sum = $a + $b;
减法: $sum = $a - $b;
乘法: $sum = $a * $b;
除法: $sum = $a / $b;
扩展资料:
PHP的加密函数有crypt()、 md5() 和sha1() 这3种, 其中crypt() 用于单向加密, 所谓的单向加密就是将需要加密的内容进行加密之后, 无法将密文转换成为可读的内容, 因此单向加密的应用范围较狭窄, 一般用于用户名认证和密码输入等情况。
当用户进入系统时,只需要将密文口令输 入,经过系统验证与存储的口令一致, 即可通过。
sha1() 函数使用了SHA-1的散列算法,其原理与md5() 类似。
参考资料来源:百度百科-PHP (超文本预处理器)
自定义名为Number的类,用于实现两个数字的四则运算。PHP!在线等!急!
?php
class Number{
private $na;
private $nb;
private $symbol;
private $result;
function __construct(){
}
public function getResult($_na,$_nb,$_symbol){
$this-na = $_na;
$this-nb = $_nb;
$this-symbol = $_symbol;
switch ($this-symbol)
{
case '+':
$this-symbol = '+';
echo "$this-na + $this-nb = ". $this-result = $this-na + $this-nb;
break;
case '-':
$this-symbol = '-';
echo "$this-na - $this-nb = ". $this-result = $this-na - $this-nb;
break;
case '*':
$this-symbol = '*';
echo "$this-na * $this-nb = ". $this-result = $this-na * $this-nb;
break;
case '/':
$this-symbol = '/';
$this-check($this-nb);
break;
default:
$this-symbol = '+';
echo "$this-na + $this-nb = ". $this-result = $this-na + $this-nb;
}
}
private function check($_nb){
$this-nb = $_nb;
if($this-nb==0){
echo "除数不能为零!";
}else{
echo "$this-na / $this-nb = ". $this-result = $this-na / $this-nb;
}
}
}
$js = new Number();
$js-getResult(3,2,"*"); //符号 为 + - * /
?
使用PHP编程。一个网页计算器,实现简单四则运算
把下面内容存成PHP格式,就OK了
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title四则运算/title
/head
body
form id="form1" name="form1" method="post" action=""
p
input name="y" type="text" id="y" size="10" /
select name="y0" id="y0"
option+/option
option-/option
option*/option
option//option
/select
input name="y1" type="text" id="y1" size="10" /
input type="submit" name="Submit" value="计算" /
/p
p /p
p /p
/form
?php
function make_safe($variable) {
$variable = addslashes(trim($variable));
return $variable;
}
$y0=make_safe($_REQUEST["y0"]);
$y1=make_safe($_REQUEST["y1"]);
$y=make_safe($_REQUEST["y"]);
if ($y0 != "")
{
switch($y0)
{
case "+":
$chaxuntj =$y+$y1;
break;
case "-":
$chaxuntj =$y-$y1;
break;
case "*":
$chaxuntj =$y*$y1;
break;
case "/":
$chaxuntj =$y/$y1;
break;
default:
}
echo $y.$y0.$y1."=".$chaxuntj;
}
?
/body
/html