首页 > 编程技术 > php

Email URL的判断和自动转换函数

发布时间:2016-11-25 16:53

<?php
function validateEmail($email)
{ return eregi("^[_a-z0-9-] (.[_a-z0-9-] )*@[a-z0-9-] (.[a-z0-9-] )*(.[a-z]{2,3})$", $email);
}

function validateURL($url)
{ return eregi("^((ht|f)tp://)((([a-z0-9-] (.[a-z0-9-] )*(.[a-z]{2,3}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[a-z0-9~#%&'_ =:?.-]*)*)$", $url);
}

function convertURLS($text)
{ $text = eregi_replace("((ht|f)tp://www.|www.)([a-z0-9-] (.[a-z0-9-] )*(.[a-z]{2,3})((/|?)[a-z0-9~#%&/'_ =:?.-]*)*)", "http://www.3", $text);
$text = eregi_replace("((ht|f)tp://)((([a-z0-9-] (.[a-z0-9-] )*(.[a-z]{2,3}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[a-z0-9~#%&'_ =:?.-]*)*)", "<a href="

DOM XML functions
These functions are only available if PHP was configured with --with-dom=[DIR], using the GNOME xml library. You will need at least libxml-2.0.0 (the beta version will not work). These functions have been added in PHP4.

This module defines the following constants:

Table 1. XML constants

Constant Value Description
XML_ELEMENT_NODE 1
XML_ATTRIBUTE_NODE 2
XML_TEXT_NODE 3
XML_CDATA_SECTION_NODE 4
XML_ENTITY_REF_NODE 5
XML_ENTITY_NODE 6
XML_PI_NODE 7
XML_COMMENT_NODE 8
XML_DOCUMENT_NODE 9
XML_DOCUMENT_TYPE_NODE 10
XML_DOCUMENT_FRAG_NODE 11
XML_NOTATION_NODE 12
XML_GLOBAL_NAMESPACE 1
XML_LOCAL_NAMESPACE 2

This module defines a number of classes. The DOM XML functions return a parsed tree of the XML document with each node being an object belonging to one of these classes.

xmldoc
(PHP4 >= 4.0b4)

xmldoc -- Creates a DOM object of an XML document
Description

object xmldoc (string str)


The function parses the XML document in str and returns an object of class "Dom document", having the properties "doc" (resource), "version" (string) and "type" (long).

xmldocfile
(PHP4 >= 4.0b4)

xmldocfile -- Creates a DOM object from XML file
Description

object xmldocfile (string filename)


The function parses the XML document in the file named filename and returns an object of class "Dom document", having the properties "doc" (resource), "version" (string).

xmltree
(PHP4 >= 4.0b4)

xmltree -- Creates a tree of php objects from XML document
Description

object xmltree (string str)


The function parses the XML document in str and returns a tree PHP objects as the parsed document.

<?php
class Segmentation {
var $options = array('lowercase' => TRUE,
'segment_english' => FALSE);
var $dict_name = 'Unknown';
var $dict_words = array();
function setLowercase($value) {
if ($value) {
$this->options['lowercase'] = TRUE;
} else {
$this->options['lowercase'] = FALSE;
}
return TRUE;
}
function setSegmentEnglish($value) {
if ($value) {
$this->options['segment_english'] = TRUE;
} else {
$this->options['segment_english'] = FALSE;
}
return TRUE;
}
function load($dict_file) {
if (!file_exists($dict_file)) {
return FALSE;
}
$fp = fopen($dict_file, 'r');
$temp = fgets($fp, 1024);
if ($temp === FALSE) {
return FALSE;
} else {
if (strpos($temp, "t") !== FALSE) {
list ($dict_type, $dict_name) = explode("t", trim($temp));
} else {
$dict_type = trim($temp);
$dict_name = 'Unknown';
}
$this->dict_name = $dict_name;
if ($dict_type !== 'DICT_WORD_W') {
return FALSE;
}
}
while (!feof($fp)) {
$this->dict_words[rtrim(fgets($fp, 32))] = 1;
}
fclose($fp);
return TRUE;
}
function getDictName() {
return $this->dict_name;
}
function segmentString($str) {
if (count($this->dict_words) === 0) {
return FALSE;
}
$lines = explode("n", $str);
return $this->_segmentLines($lines);
}
function segmentFile($filename) {
if (count($this->dict_words) === 0) {
return FALSE;
}
$lines = file($filename);
return $this->_segmentLines($lines);
}
function _segmentLines($lines) {
$contents_segmented = '';
foreach ($lines as $line) {
$contents_segmented .= $this->_segmentLine(rtrim($line)) . " n";
}
do {
$contents_segmented = str_replace(' ', ' ', $contents_segmented);
} while (strpos($contents_segmented, ' ') !== FALSE);
return $contents_segmented;

字符串截取函数开始        function csubStr($str,$start,$len)
        {
                $strlen=strlen($str);
                $clen=0;
                for($i=0;$i<$strlen;$i++,$clen++)
                {
                        if ($clen>=$start+$len)
                        break;

                        if(ord(substr($str,$i,1))>0xa0)
                        {
                                if ($clen>=$start)
                                $tmpstr.=substr($str,$i,2);
                                $i++;
                        }
                        else
                        {
                                if ($clen>=$start)
                                $tmpstr.=substr($str,$i,1);
                        }
        }
       
        return $tmpstr;
        }
       
    //------------------------------字符串截取函数结束-------------------------------------------

/*使用方法:
<?php
$str=csubStr("ipod光环太耀眼 苹果的电脑本业该怎么办?",0,20);
echo $str;
?>       


 对于magic_quotes_gpc有两种情况,第一种就是
magin_quotes_gpc=on
与magin_quotes_gpc=off
 下面我们就来举列说明.:
当magin_quotes_gpc=on时.

我们可以不对输入和输出数据库的字符串数据作 ,addslashes()和stripslashes()的操作,数据也会正常显示。

如果此时你对输入的数据作了addslashes()处理,那么在输出的时候就必须使用stripslashes()去掉多余的反斜杠。

2. 对于magic_quotes_gpc=off 的情况

必须使用addslashes()对输入数据进行处理,但并不需要使用stripslashes()格式化输出 因为addslashes()并未将反斜杠一起写入数据库,只是帮助mysql完成了sql语句的执行。

补充:

magic_quotes_gpc 作用范围是:WEB客户服务端;作用时间:请求开始时,例如当脚本运行时.
magic_quotes_runtime 作用范围:从文件中读取的数据或执行exec()的结果或是从SQL查询中得到的;作用时间:每次当脚本访问运行状态中产生的数据
标签:[!--infotagslink--]

您可能感兴趣的文章: