❶ php里怎么计算标准差
你在数学扩展里找找 先要要开启数学扩展 改一个下php.ini文件
❷ php 数组 将指定元素移至末尾
$arr = array(0,3,5,0,0,7,1,9,0,8);
$count = count($arr);
$remove_arr = array();
for($i=0;$i<=$count;$i++){
if($arr[$i] === 0) {
array_push($arr, $arr[$i]);
array_push($remove_arr, $i);
}
}
foreach($arr as $k=> $v) {
if(in_array($k, $remove_arr)){
unset($arr[$k]);
}
}
echo '<pre>';
var_mp($arr);die;
❸ php怎么访问url,如果访问如果返回true访问失败返回false,不要跳转, 就判断访问是否成
php访问url的四种方式
1.fopen方式
//访问指定URL函数
[php] view plain
print?
function access_url($url) {
if ($url=='') return false;
$fp = fopen($url, 'r') or exit('Open url faild!');
if($fp){
while(!feof($fp)) {
$file.=fgets($fp)."";
}
fclose($fp);
}
return $file;
}
2.file_get_contents方式(打开远程文件的时候会造成CPU飙升。file_get_contents其实也可以post)
[php] view plain
print?
$content = file_get_contents("httttp://wwww..com");
3.curl方式
[php] view plain
print?
function curl_file_get_contents($rl){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
4.fsockopen方式(只能获取网站主页信息,其他页面不可以)
[php] view plain
print?
$fp = fsockopen("www..com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out="GET / HTTP/1.1\r\n";
$out.="Host: www..com\r\n";
$out.="Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
❹ php 如何区分 返回的是0 还是false
if($a==='false')判断是不是false
if($a===0)判断是不是0
❺ PHP表单提交做判断的问题
64行有误,语法错误:
if(form.yzbm.value.length != 6 && form.yzbm.value != ){
另外给你一个我自己做项目经常用的验证方法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Check Form</title>
</head>
<script type="text/javascript">
//主函数
function CheckForm(oForm) {
var err_ele = null;
var ele = oForm.elements;
var haserror = false;
//遍历所有表元素
for(var i=0;i<ele.length;i++) {
//过滤元素类型
if(ele.type != 'submit' && ele.type != 'hidden' && ele.type != 'button') {
//是否需要验证标签
var required = ele[i].getAttribute('required');
if(required!="undefined" && (required==""||required=="true"||required=="yes") ) {
if(!validate(ele[i])) {
if(err_ele==null)
err_ele = ele[i];
haserror = true;
break;
}
}
}
}
//判断是否有没有通过验证的项目
if(haserror) {
err_ele.focus();
return false;
} else {
return true;
}
}
//得到表单元素的值
function getvalue(ele) {
var type = ele.getAttribute('type');
switch(type) {
case 'text':
case 'hidden':
case 'password':
case 'file':
case "select-one":
case 'textarea':
return ele.value;
}
}
//检测函数
function validate(ele) {
//得到设定的检测函数
var fun = ele.getAttribute('fun');
//自定义提示语句
var custommsg = ele.getAttribute('msg');
if(fun!=null) {
var checkarr = executeFunc(fun,ele);
if(checkarr[2] == 'regxp') { //正则表达式处理
if(!regValidate(getvalue(ele),checkarr[0])) {
//如果有自定义提示语句则使用自定义提示语句
if(custommsg) {
alert(custommsg);
} else {
alert(checkarr[1]);
}
return false;
}
} else if(checkarr[2] == 'custom') { //函数自行逻辑处理
//如果验证通过
if(!checkarr[0]) {
//如果有自定义提示语句则使用自定义提示语句
if(custommsg) {
alert(custommsg);
} else {
alert(checkarr[1]);
}
return false;
}
}
}
return true;
}
//运行函数
function executeFunc(name,element) {
//匹配函数是否带有参数
if(name.match(/^[\w]+\([\w,\'\"]+\);?$/)) {
return eval(name.replace(/^([\w]+)\(([\w,\'\"]+)\);?$/,'$1($2,element)'));
} else {
return eval(name.match(/^[\w]+\(\)$/) ? name : name + '(element)');
}
}
//
//判定某个值与表达式是否相符
function regValidate(value,sReg) {
//字符串->正则表达式,不区分大小写
var reg = new RegExp(sReg ,"i");
if(reg.test(value)) {
return true;
} else {
return false;
}
}
//////////////////////////////////验证规则定义///////////////////////////////
// 正则类验证
function UserName() {
var rt = new Array();
rt[0] = '^([a-zA-Z0-9]|[._]){4,19}$';
rt[1] = "用户名必须为4-19个字母和数字组成";
rt[2] = 'regxp';
return rt;
}
function PassWord() {
var rt = new Array();
rt[0] = '^([a-zA-Z0-9]|[._]){6,19}$';
rt[1] = "密码必须为6-19个字母和数字组成";
rt[2] = 'regxp';
return rt;
}
function notBlank(){
var rt = new Array();
rt[0] = "^\\S+$";
rt[1] = "该项不能为空,且不能含有空格!";
rt[2] = 'regxp';
return rt;
}
function required(){
var rt = new Array();
rt[0] = "^\\S";
rt[1] = "该项不能为空!";
rt[2] = 'regxp';
return rt;
}
//判断email
function isEmail() {
var rt = new Array();
rt[0] = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
rt[1] = "该项填写的EMAIL格式不正确!";
rt[2] = 'regxp';
return rt;
}
//只能输入中文
function onlyZh() {
var rt = new Array();
rt[0] = "^[\u0391-\uFFE5]+$";
rt[1] = "该项只能输入中文!";
rt[2] = 'regxp';
return rt;
}
//只可输入英文
function onlyEn() {
var rt = new Array();
rt[0] = "^[A-Za-z]+$";
rt[1] = "该项只能输入英文!";
rt[2] = 'regxp';
return rt;
}
function enOrNum() {
var rt = new Array();
rt[0] = "^[A-Za-z0-9]+$";
rt[1] = "该项只能输入英文和数字,且不能有空格!";
rt[2] = 'regxp';
return rt;
}
function isPhone() {
var rt = new Array();
rt[0] = "^((\\(\\d{2,3}\\))|(\\d{3}\\-))?(\\(0\\d{2,3}\\)|0\\d{2,3}-)?[1-9]\\d{6,7}(\\-\\d{1,4})?$";
rt[1] = "应输入正确的电话号码格式!";
rt[2] = 'regxp';
return rt;
}
// 自定义类验证函数
function isIdCard(ele) {
var rt = new Array();
rt[0] = false;
rt[1] = "应输入正确身份证号!";
rt[2] = 'custom';
var Reg_15 = /^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{2})(\w)$/;
var Reg_18 = /^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\w)$/;
var num = ele.value;
var len = num.length;
if (len == 15) {
if (Reg_15.test(num))
rt[0] = true;
}
else if(len == 18) {
if (Reg_18.test(num))
rt[0] = true;
}
return rt;
}
function rePassword(ID,ele) {
var rt = new Array();
rt[0] = false;
rt[1] = "再次密码输入不一致!";
rt[2] = 'custom';
var password = document.getElementById(ID).value;
if(password != '' || ele.value != ''){
if(password == ele.value)
rt[0] = true;
}
return rt;
}
</script>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return CheckForm(this);">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="20%" align="right">用户名:</td>
<td><input type="text" name="username" id="username" required="true" fun="UserName" msg="自定义提示信息:用户名不正确,请重新输入!" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password" id="password" required="true" fun="PassWord" /></td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td><input type="password" name="repassword" id="repassword" required="true" fun="rePassword('password')" /></td>
</tr>
<tr>
<td align="right">电子邮件:</td>
<td><input type="text" name="email" id="email" required="true" fun="isEmail" /></td>
</tr>
<tr>
<td align="right">身份证号:</td>
<td><input type="text" name="idcard" id="idcard" required="true" fun="isIdCard" /></td>
</tr>
<tr>
<td align="right">全中文项:</td>
<td><input type="text" name="chinese" id="chinese" required="true" fun="onlyZh" /></td>
</tr>
<tr>
<td align="right">其它:</td>
<td><input type="text" name="notblank" id="notblank" required="true" fun="notblank" /></td>
</tr>
<tr>
<td align="right"></td>
<td><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>
❻ php判断是否是有效IP地址的方法
提供下面两个方法,供选择:
functioncheckIp($ip)
{
$arr=explode('.',$ip);
if(count($arr)!=4){
returnfalse;
}else{
for($i=0;$i<4;$i++){
if(($arr[$i]<'0')||($arr[$i]>'255')){
returnfalse;
}
}
}
returntrue;
}
functionisIp($ip){
if(preg_match('/^((?:(?:25[0-5]|2[0-4]d|((1d{2})|([1-9]?d))).){3}(?:25[0-5]|2[0-4]d|((1d{2})|([1-9]?d))))$/',$ip)){
return1;
}else{
return0;
}
}
❼ php如何验证网址是否正确
public function getUrlParams()
{
if ($this->_urlParams === null)
{
$pa = @parse_url($this->getUrl());
$pa['scheme'] = isset($pa['scheme']) ? strtolower($pa['scheme']) : 'http';
if ($pa['scheme'] !== 'http' && $pa['scheme'] !== 'https')
{
trigger_error("Invalid url scheme `{$pa['scheme']}`", E_USER_WARNING);
return false;
}
if (!isset($pa['host']))
{
trigger_error("Invalid request url, host required", E_USER_WARNING);
return false;
}
if (!isset($pa['path']))
$pa['path'] = '/';
// basic auth
if (isset($pa['user']) && isset($pa['pass']))
$this->applyBasicAuth($pa['user'], $pa['pass']);
// convert host to IP address
$port = isset($pa['port']) ? intval($pa['port']) : ($pa['scheme'] === 'https' ? 443 : 80);
$pa['ip'] = $this->hasHeader('x-server-ip') ?
$this->getHeader('x-server-ip') : self::getIpAddr($pa['host']);
$pa['conn'] = ($pa['scheme'] === 'https' ? 'ssl' : 'tcp') . '://' . $pa['ip'] . ':' . $port;
// host header
if (!$this->hasHeader('host'))
$this->setHeader('host', strtolower($pa['host']));
else
$pa['host'] = $this->getHeader('host');
$this->_urlParams = $pa;
}
return $this->_urlParams;
}
public function getUrlParam($key)
{
$pa = $this->getUrlParams();
return isset($pa[$key]) ? $pa[$key] : null;
}
❽ php foreach 返回问题
<?php
/**
*不是很看的懂你这个程序是干啥的,英文字面上意思是数据验证的,源代码太长很多不必要的地方
*ClassValidate
*/
classValidate{
publicfunctiondata_verify($_verify){
//必要数据验证
if(empty($_verify))returnfalse;
//报错行数计算
$num=0;
//正确代码数组
$successData=array('11'=>'test','22'=>'test1','33'=>'test2','44'=>'test3');
//遍历验证
foreach($_verifyas$key=>$value){
//正确进入
if(!empty($successData[$value]))
{
$data['content']=$successData[$value];
}else{
//如果有错误会在这里输出,当然你可以有错误就直接返回returnfalse;或者记录在报错数组!你要什么逻辑代码自己改喽~
echo'第'.$num.'个数组下标有误!';
}
$num++;
}
return$data;
}
}
$validate=newValidate();
$request=$validate->data_verify(array('test'=>'11','test1'=>'22','test2'=>'33','test3'=>'44'));
var_mp($request);