❶ 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);