<?php
/**
* Page function: Common form verification class
* Author: Follow the wind with pleasure
* Establishment time: 2006-3-6
* QQ:276624915
*/
class class_post
{
//Verify whether it is a letter/number combination of the specified length
function fun_text1($num1,$num2,$str)
{
Return (preg_match("/^[a-zA-Z0-9]{".$num1.",".$num2."}$/",$str))?true:false;
}
//Verify whether it is a specified length number
function fun_text2($num1,$num2,$str)
{
return (preg_match("/^[0-9]{".$num1.",".$num2."}$/i",$str))?true:false;
}
//Verify whether it is a Chinese character with a specified length
function fun_font($num1,$num2,$str)
{
// preg_match("/^[\xa0-\xff]{1,4}$/", $string);
return (preg_match("/^([\x81-\xfe][\x40-\xfe]){".$num1.",".$num2."}$/",$str))?true:false;
}
//Verify ID number
function fun_status($str)
{
return (preg_match('/(^([\d]{15}|[\d]{18}|[\d]{17}x)$)/',$str))?true:false;
}
//Verify the email address
function fun_email($str){
return (preg_match('/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$/',$str))?true:false;
}
//Verify the phone number
function fun_phone($str)
{
return (preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/",$str))?true:false;
}
//Verify the zip code
function fun_zip($str)
{
return (preg_match("/^[1-9]\d{5}$/",$str))?true:false;
}
//Verify the URL
function fun_url($str)
{
return (preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/",$str))?true:false;
}
// Data library escape Special characters The incoming value can be a string or a one-dimensional array
function data_join(&$data)
{
if(get_magic_quotes_gpc() == false)
{
if (is_array($data))
{
foreach ($data as $k => $v)
{
$data[$k] = addslashes($v);
}
}
else
{
$data = addslashes($data);
}
}
Return $data;
}
// Data out of database restore Special characters The incoming value can be a string or a one/two-dimensional array
function data_revert(&$data)
{
if (is_array($data))
{
foreach ($data as $k1 => $v1)
{
if (is_array($v1))
{
foreach ($v1 as $k2 => $v2)
{
$data[$k1][$k2] = stripslashes($v2);
}
}
else
{
$data[$k1] = stripslashes($v1);
}
}
}
else
{
$data = stripslashes($data);
}
Return $data;
}
// Data display, restore, data format, mainly used for content output, the incoming value can be a string or a one/two-dimensional array
// The data_revert() should be first before executing this method, and the form content does not need to be restored.
function data_show(&$data)
{
if (is_array($data))
{
foreach ($data as $k1 => $v1)
{
if (is_array($v1))
{
foreach ($v1 as $k2 => $v2)
{
$data[$k1][$k2]=nl2br(htmlspecialchars($data[$k1][$k2]));
$data[$k1][$k2]=str_replace(" "," ",$data[$k1][$k2]);
$data[$k1][$k2]=str_replace("\n","<br>\n",$data[$k1][$k2]);
}
}
else
{
$data[$k1]=nl2br(htmlspecialchars($data[$k1]));
$data[$k1]=str_replace(" "," ",$data[$k1]);
$data[$k1]=str_replace("\n","<br>\n",$data[$k1]);
}
}
}
else
{
$data=nl2br(htmlspecialchars($data));
$data=str_replace(" "," ",$data);
$data=str_replace("\n","<br>\n",$data);
}
Return $data;
}
}
?>
/**
* Page function: Common form verification class
* Author: Follow the wind with pleasure
* Establishment time: 2006-3-6
* QQ:276624915
*/
class class_post
{
//Verify whether it is a letter/number combination of the specified length
function fun_text1($num1,$num2,$str)
{
Return (preg_match("/^[a-zA-Z0-9]{".$num1.",".$num2."}$/",$str))?true:false;
}
//Verify whether it is a specified length number
function fun_text2($num1,$num2,$str)
{
return (preg_match("/^[0-9]{".$num1.",".$num2."}$/i",$str))?true:false;
}
//Verify whether it is a Chinese character with a specified length
function fun_font($num1,$num2,$str)
{
// preg_match("/^[\xa0-\xff]{1,4}$/", $string);
return (preg_match("/^([\x81-\xfe][\x40-\xfe]){".$num1.",".$num2."}$/",$str))?true:false;
}
//Verify ID number
function fun_status($str)
{
return (preg_match('/(^([\d]{15}|[\d]{18}|[\d]{17}x)$)/',$str))?true:false;
}
//Verify the email address
function fun_email($str){
return (preg_match('/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$/',$str))?true:false;
}
//Verify the phone number
function fun_phone($str)
{
return (preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/",$str))?true:false;
}
//Verify the zip code
function fun_zip($str)
{
return (preg_match("/^[1-9]\d{5}$/",$str))?true:false;
}
//Verify the URL
function fun_url($str)
{
return (preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/",$str))?true:false;
}
// Data library escape Special characters The incoming value can be a string or a one-dimensional array
function data_join(&$data)
{
if(get_magic_quotes_gpc() == false)
{
if (is_array($data))
{
foreach ($data as $k => $v)
{
$data[$k] = addslashes($v);
}
}
else
{
$data = addslashes($data);
}
}
Return $data;
}
// Data out of database restore Special characters The incoming value can be a string or a one/two-dimensional array
function data_revert(&$data)
{
if (is_array($data))
{
foreach ($data as $k1 => $v1)
{
if (is_array($v1))
{
foreach ($v1 as $k2 => $v2)
{
$data[$k1][$k2] = stripslashes($v2);
}
}
else
{
$data[$k1] = stripslashes($v1);
}
}
}
else
{
$data = stripslashes($data);
}
Return $data;
}
// Data display, restore, data format, mainly used for content output, the incoming value can be a string or a one/two-dimensional array
// The data_revert() should be first before executing this method, and the form content does not need to be restored.
function data_show(&$data)
{
if (is_array($data))
{
foreach ($data as $k1 => $v1)
{
if (is_array($v1))
{
foreach ($v1 as $k2 => $v2)
{
$data[$k1][$k2]=nl2br(htmlspecialchars($data[$k1][$k2]));
$data[$k1][$k2]=str_replace(" "," ",$data[$k1][$k2]);
$data[$k1][$k2]=str_replace("\n","<br>\n",$data[$k1][$k2]);
}
}
else
{
$data[$k1]=nl2br(htmlspecialchars($data[$k1]));
$data[$k1]=str_replace(" "," ",$data[$k1]);
$data[$k1]=str_replace("\n","<br>\n",$data[$k1]);
}
}
}
else
{
$data=nl2br(htmlspecialchars($data));
$data=str_replace(" "," ",$data);
$data=str_replace("\n","<br>\n",$data);
}
Return $data;
}
}
?>