<?php
其餘
isset() 變量是否存在
boolean empty() 檢查變量是否存在,並判斷值是否爲非空或非0
void unset() 銷燬變量
header('Content-Type: text/html; charset=utf-8');
method_exists($obj, $method) 判斷對象的方法是否可用
file_exists($file) 判斷文件是否存在
function_exists();
class_exists($class_name);
gettype();獲取數據類型
set_magic_quotes_runtime() 0 for off, 1 for on 當遇到反斜杆、單引號,將會自動加上一個反斜杆,保護系統和數據庫的安全
ini_set();php
安全
function strReplace($str)
{
$strResult = $str;
if(!get_magic_quotes_gpc())//判斷設置是否開啓
{
$strResult = addslashes($strResult);//轉換sql語句特殊字符
}
return $strResult;
}html
function quotes($content)
{
//若是magic_quotes_gpc=Off,那麼就開始處理
if (!get_magic_quotes_gpc())
{
//判斷$content是否爲數組
if (is_array($content))
{
//若是$content是數組,那麼就處理它的每個單無
foreach ($content as $key=>$value)
{
$content[$key] = addslashes($value);
}
}
else
{
//若是$content不是數組,那麼就僅處理一次
addslashes($content);
}
}
//返回$content
return $content;
}node
編碼轉換
string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )
iconv();mysql
時間
date_default_timezone_set("PRC");
date("Y-m-d H:i:s");
time();
date("Y-m-d H:i:s",time()+3600)
ini_set('date.timezone', 'PRC');
msec sec microtime() 以秒返回時間戳 explode(' ', microtime())正則表達式
魔術方法
__construct() 當實例化一個對象的時候,這個對象的這個方法首先被調用。
__destruct() 當刪除一個對象或對象操做終止的時候,調用該方法。
__get() 當試圖讀取一個並不存在的屬性的時候被調用。
__set() 當試圖向一個並不存在的屬性寫入值的時候被調用。
__call() 當試圖調用一個對象並不存在的方法時,調用該方法。
__toString() 當打印一個對象的時候被調用
__clone() 當對象被克隆時,被調用
__isset()
__unset()
__autoload($classname)
__sleep()
__wakeup()算法
系統常量
__FILE__ 當前文件名
__LINE__ 當前行數
__FUNCTION__ 當前函數名
__CLASS__ 當前類名
__METHOD__ 當前對象的方法名
PHP_OS 當前系統
PHP_VERSION php版本
DIRECTORY_SEPARATOR 根據系統決定目錄的分隔符 /\
PATH_SEPARATOR 根據系統決定環境變量的目錄列表分隔符 ; :
E_ERROR 1
E_WARNING 2
E_PARSE 4
E_NOTICE 8
M_PI 3.141592
$_SERVER
$_ENV 執行環境提交至腳本的變量
$_GET
$_POST
$_REQUEST
$_FILES
$_COOKIE
$_SESSION
$_GLOBALSsql
輸出
echo //Output one or more strings
print //Output a string
print_r() //打印關於變量的易於理解的信息。
var_dump() //打印變量的相關信息
var_export() //輸出或返回一個變量的字符串表示
printf("%.1f",$num) //Output a formatted string
sprintf() //Return a formatted string數據庫
錯誤處理
@1/0
error_reporting(E_ALL) 顯示全部錯誤
error_reporting(0)
trigger_error("Cannot divide by zero", E_USER_ERROR);
try
{
throw new Exception("執行失敗");
}
catch (Exception $ex)
{
echo $ex;
}express
字符串處理
string trim("eee ") trim ('ffffe','e') //ltrim rtrim
array explode(".", "fff.ff.f") 按指定字符切割
string implode(".", $array) 別名:join 把數組值數據按指定字符鏈接起來
array str_split("eeeeeeee",4) 按長度切割字符串
array split("-","fff-ff-f") 按指定字符切割
int strlen('ffffffff') 取字符長度
string substr ( string $string , int $start [, int $length ] )
substr($a,-2, 2) 截取字符
int substr_count($text, 'is') 字符串出現的次數
string strstr($text, 'h') 第一次出現h後的字符串 //別名:strchr
int strpos($text, 'h') 第一次出現h的位置
strrpos();最後一次出現h的位置
str_replace('a', 'ttt', $t) 把$t裏的'a'替換爲'ttt'
strtr($t,'is','ppp') 把$t中'is'替換成'ppp'
strtr("hi all, I said hello", array("hello" => "hi")) 把'hello'轉換成'hi'
string md5_file('1.txt',false) 文件數據md5加密
int strcmp(string str1, string str2) 字符串比較
int strcasecmp(string str1, string str2) 忽略大小寫
string str_pad($i, 10, "-=", STR_PAD_LEFT) 在原字符左邊補'-=',直到新字符串長度爲10
STR_PAD_RIGHT
STR_PAD_BOTH
string str_repeat('1', 5) 重複5個1
void parse_str('id=11'); echo $id; 將字串符解析爲變量
array preg_grep("/^(\d+)?\.\d+$/", array(11.2,11,11.2)) 匹配數據
array preg_split ("/[\s,]+/", "hypertext language,programming"); 按指定的字符切割
array pathinfo(string path [, int options]) 返回文件路徑的信息
string basename ( string path [, string suffix] ) 返回路徑中的文件名部分
string dirname ( string path ) $_SERVER[PHP_SELF] 返回路徑中的目錄部分
string nl2br("foo isn't\n bar") "foo isn't<br> bar" 把換行轉成<br>
string chr ( int ascii ) *
mixed str_word_count ( string string [, int format [, string charlist]] )
string str_shuffle ('abc') 打亂字符串順序
string strrev($str) * 翻轉一個字符串
string strtolower($str) * 將字符串 $str 的字符所有轉換爲小寫的
string strtoupper($str) * 將字符串 $str 的字符所有轉換爲大寫的
string ucfirst ($str) * 將字符串 $str 的第一個單詞的首字母變爲大寫。
string ucwords($str) * 將字符串 $str 的每一個單詞的首字母變爲大寫。apache
string addslashes("I'm") I\'m 使用反斜線引用字符串 這些字符是單引號(')、雙引號(")、反斜線(\)與 NUL(NULL 字符)
string stripcslashes("I\'m") I'm 將用addslashes()函數處理後的字符串返回原樣
strip_tags("<p>tt</p>", '<p>') 去除html、xml、php標記,第二個參數用來保留標記
string urlencode(string str)
string urldecode(string str)
string htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES) 轉換特殊字符爲HTML字符編碼
<a href='test'>Test</a>
ENT_COMPAT –對雙引號進行編碼,不對單引號進行編碼
ENT_QUOTES –對單引號和雙引號進行編碼
ENT_NOQUOTES –不對單引號或雙引號進行編碼
string htmlentities('<p>ff</p>', ENT_QUOTES) 轉換特殊字符爲HTML字符編碼,中文會轉成亂碼
數組處理
int count( mixed var [, int mode] ) 別名:sizeof() 取數組長度
string implode(".", $array) 別名:join 把數組值數據按指定字符鏈接起來
array explode(".", "fff.ff.f") 按指定字符切割
array range(0, 6, 2) 返回數組 array(0,2,4,6) 第一個參數爲起使數,第二個參數爲結束數,第三個參數爲數據增長步長
int array_push($a, "3", 1) 把'3'、'1'壓入$a,將一個或多個單元壓入數組的末尾(入棧),第二個參數開始就是壓入的數據
void unset ( mixed var [, mixed var [, ...]] )
array array_pad ($a, 5, 's')用's'將數組填補到指定長度
bool shuffle ( array $array ) 將數組打亂
mixed array_rand ( array input [, int num_req] )從數組中隨機取出一個或多個單元的索引或鍵名
array array_count_values ( array input )統計數組中全部的值出現的次數
array array_combine ( array keys, array values ) 建立一個數組,用一個數組的值做爲其鍵名,另外一個數組的值做爲其值
bool array_key_exists ( mixed key, array search )檢查給定的鍵名或索引是否存在於數組中
mixed array_search ( mixed needle, array haystack [, bool strict] )在數組中搜索給定的值,若是成功則返回相應的鍵名
bool is_array ( mixed var )
bool in_array ( mixed needle, array haystack [, bool strict] )檢查數組中是否存在某個值
number array_sum ( array array )計算數組中全部值的和
array array_unique ( array array )移除數組中重複的值
mixed reset ( array &array )將數組的內部指針指向第一個單元
mixed current ( array &array )
mixed next ( array &array )
mixed prev ( array &array )
mixed end ( array &array )
mixed key ( array &array )
array array_keys ( array input [, mixed search_value [, bool strict]] ) 返回數組中全部的鍵名
array array_values ( array input ) 返回數組中全部的值
bool print_r ( mixed expression [, bool return] )
void var_dump ( mixed expression [, mixed expression [, ...]] )
int array_unshift ( array &array, mixed var [, mixed ...] )在數組開頭插入一個或多個單元
mixed array_shift ( array &array )將數組開頭的單元移出數組
mixed array_pop ( array &array )將數組最後一個單元彈出(出棧)
array array_splice ( array $input, int offset [, int length [, array replacement]] ) 把數組中的一部分去掉並用其它值取代
array array_merge ( array array1 [, array array2 [, array ...]] )合併一個或多個數組
array array_flip ( array trans )交換數組中的鍵和值
int extract( array var_array [, int extract_type [, string prefix]] ) 從數組中將變量導入到當前的符號表
array compact ( mixed varname [, mixed ...] ) 創建一個數組,包括變量名和它們的值
bool sort ( array &array [, int sort_flags] )從最低到最高從新安排
bool natsort($a) 用「天然排序」算法對數組排序
bool rsort ( array &array [, int sort_flags] )對數組進行逆向排序(最高到最低)
bool asort ( array &array [, int sort_flags] )對數組進行排序並保持索引關係
bool arsort ( array &array [, int sort_flags] ) 對數組進行逆向排序並保持索引關係
bool ksort ( array &array [, int sort_flags] )對數組按照鍵名排序
bool krsort ( array &array [, int sort_flags] )對數組按照鍵名逆向排序
array array_filter ( array input [, callback callback] ) 用回調函數過濾數組中的單元
bool array_walk ( array &array, callback funcname [, mixed userdata] ) 對數組中的每一個成員應用用戶函數
array array_map ( callback callback, array arr1 [, array ...] )將回調函數做用到給定數組的單元上
array array_fill ( int start_index, int num, mixed value ) 用給定的值填充數組
array_fill(5, 3, 'a')-->array(5=>'a',6=>'a',7=>'a')
array array_chunk ( array input, int size [, bool preserve_keys] )將一個數組分割成多個
smarty
模板引擎將不分析
<!--{literal}-->
<script>
function t() {
}
</script>
<!--{/literal}-->
讀取配置文件
<!--{config_load file="config.s"}-->
<!--{#site_url#}-->
<!--{$smarty.config.site_url}-->
引入文件
<!--{include file="index2.html"}-->
<!--{include_php file="/path/to/load_nav.php"}--> $trusted_dir 指定目錄下的文件
捕獲模板輸出的數據
<!--{capture name='eee'}-->
fffffffff
<!--{/capture}-->
<!--{$smarty.capture.eee}-->
循環
<{section name=loop loop=$News_IN}>
<{$News_IN[loop].NewsID}>
<{/section}>
<!--{section name=t loop=$data}-->
<tr>
<td><!--{$data[t].username}--></td>
</tr>
<!--{/section}-->
<{foreach from=$newsArray item=newsID key=k}>
新聞編號:<{$newsID.newsID}><br>
新聞內容:<{$newsID.newsTitle}><br><hr>
<{/foreach}>
判斷
<!--{if true}-->
<!--{else}-->
<!--{/if}-->
時間
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
%Y年%m月%d日 亂碼
<!--{$smarty.now|date_format:"%Y年%m月%d日 %H時%M分%S秒"}-->
修改插件:plugins/modifier.date_format.php
$format = mb_convert_encoding($format,'gbk','utf-8');
return mb_convert_encoding(strftime($format, $timestamp),'utf-8','gbk');
局部不緩存
html:
<!--{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}-->
<!--{cacheless a="aaa" b="bbbb"}-->
<!--{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}-->
<!--{/cacheless}-->
php:
$smarty->register_block('cacheless', 'smarty_block_dynamic', false);//true:緩存,false:不緩存
function smarty_block_dynamic($param, $content, &$smarty)
{
return $content;
}
php:
function insert_kk()//方法名前必須有"insert"
{
return date('Y-m-d H:i:s');
}
html:
<!--{insert name="kk"}-->
自定義方法
註冊方法
php
$smarty->register_function('test1', 'test');
function test($p)
{
return 'ffffffffff';
}
html:
<!--{test1 name="ff"}-->
------------------------------------------------
方法自定義
插件文件方式定義方法
function.test.php 文件存在plugins目錄下,方法名:smarty_function_test($params, &$smarty)
function smarty_function_test($params, &$smarty)
{
return 'fff';
}
html調用:
<!--{test name='aa' p='ff'}-->
----------------------------------------------------
插入方法
插件文件:insert.kk.php文件存於plugins目錄下
function smarty_insert_kk()
{
return date('Y-m-d H:i:s');
}
php:
function insert_kk()//方法名前必須有"insert"
{
return date('Y-m-d H:i:s');
}
html:
<!--{insert name="kk"}-->
-------------------------------------------------
管道符自定義方法
插件文件方式定義方法
modifier.test.php 文件存在於plugins目錄下,方法名: function smarty_modifier_test($str, $str2)
function smarty_modifier_test($str, $str2)
{
return $str.$str2;
}
html調用:
<!--{'ff'|test:'tt'}-->
php:
function eee($a)
{
return 'ffffffffffffff';
}
html:
<!--{''|@eee}-->
if語句
eq相等,
ne、neq不相等,
gt大於
gte、ge大於等於,
lte、le 小於等於,
not非, mod求模。
is [not] div by是否能被某數整除,
is [not] even是否爲偶數,
$a is [not] even by $b 即($a / $b) % 2 == 0
is [not] odd是否爲奇
$a is not odd by $b即($a / $b) % 2 != 0
XML
sax
xml:
<--?xml version="1.0" encoding="utf-8"?-->
<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>Jack Herrington</author>
<title>Podcasting Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>做者</author>
<title>標題</title>
<publisher>出版者</publisher>
</book>
</books>
php:
$g_books = array();
$g_elem = null;
function startElement( $parser, $name, $attrs )
{
global $g_books, $g_elem;
if ( $name == 'BOOK' ) $g_books []= array();
$g_elem = $name;
}
function endElement( $parser, $name )
{
global $g_elem;
$g_elem = null;
}
function textData( $parser, $text )
{
global $g_books, $g_elem;
if ( $g_elem == 'AUTHOR' ||
$g_elem == 'PUBLISHER' ||
$g_elem == 'TITLE' )
{
$g_books[ count( $g_books ) - 1 ][ $g_elem ] = $text;
}
}
$parser = xml_parser_create();
xml_set_element_handler( $parser, "startElement", "endElement" );
xml_set_character_data_handler( $parser, "textData" );
$f = fopen( '1.xml', 'r' );
while($data = fread( $f, 4096 ))
{
xml_parse( $parser, $data );
}
xml_parser_free( $parser );
foreach( $g_books as $book )
{
echo $book['TITLE']." - ".$book['AUTHOR']." - ";
echo $book['PUBLISHER']."<br>";
}
DomDocument()
xml:
<--?xml version="1.0" encoding="utf-8"?-->
<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>Jack Herrington</author>
<title>Podcasting Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>做者</author>
<title>標題</title>
<publisher>出版者</publisher>
</book>
</books>
php讀取:
$doc = new DOMDocument();
$doc->load( "1.xml");
$books = $doc->getElementsByTagName( "book" );
foreach( $books as $book )
{
$authors = $book->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$publishers = $book->getElementsByTagName( "publisher" );
$publisher = $publishers->item(0)->nodeValue;
$titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
echo "$title - $author - $publisher<br>";
}
php生成:
$books = array();
$books [] = array(
'title' => 'PHP Hacks',
'author' => 'Jack Herrington',
'publisher' => "O'Reilly"
);
$books [] = array(
'title' => 'Podcasting Hacks',
'author' => 'Jack Herrington',
'publisher' => "O'Reilly"
);
$doc = new DOMDocument();
$doc->formatOutput = true;
$r = $doc->createElement( "books" );
$doc->appendChild( $r );
foreach( $books as $book )
{
$b = $doc->createElement( "book" );
$author = $doc->createElement( "author" );
$author->appendChild($doc->createTextNode( $book['author'] ));
$b->appendChild( $author );
$title = $doc->createElement( "title" );
$title->appendChild($doc->createTextNode( $book['title'] ));
$b->appendChild( $title );
$publisher = $doc->createElement( "publisher" );
$publisher->appendChild($doc->createTextNode( $book['publisher'] ));
$b->appendChild( $publisher );
$r->appendChild( $b );
}
echo $doc->saveXML();
echo $doc->save('222.xml');
SimpleXML
xml:
<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</books>
php:
$xml = new SimpleXMLElement('1.xml', NULL, TRUE);
echo $xml->book[0]->author."___".$xml->book[0]->title."___".$xml->book[0]->publisher;
正則
ereg系列的正則表達式不須要定屆符,preg系列的才須要,而且定界符能夠本身選擇,只有先後一對就行,好比咱們通常使用/符號,可是若是裏面有/須要匹配那麼就須要使用\/來表示,當/須要出現屢次的時候,這樣就不方便,咱們就可使用其餘的定界符,好比|
正則特殊字符
. \ + * ? [ ^ ] $ ( ) { } = ! < > | :
由原子(普通字符,如英文字符)、
元字符(有特殊功用的字符)
模式修正字符
一個正則表達式中,至少包含一個原子
所有符號解釋
\ 將下一個字符標記爲一個特殊字符、或一個原義字符、或一個 向後引用、或一個八進制轉義符。例如,'n' 匹配字符 "n"。'\n' 匹配一個換行符。序列 '\\' 匹配 "\" 而 "\(" 則匹配 "("。
^ 匹配輸入字符串的開始位置。若是設置了 RegExp 對象的 Multiline 屬性,^ 也匹配 '\n' 或 '\r' 以後的位置。
$ 匹配輸入字符串的結束位置。若是設置了RegExp 對象的 Multiline 屬性,$ 也匹配 '\n' 或 '\r' 以前的位置。
* 匹配前面的子表達式零次或屢次。例如,zo* 能匹配 "z" 以及 "zoo"。* 等價於{0,}。
+ 匹配前面的子表達式一次或屢次。例如,'zo+' 能匹配 "zo" 以及 "zoo",但不能匹配 "z"。+ 等價於 {1,}。
? 匹配前面的子表達式零次或一次。例如,"do(es)?" 能夠匹配 "do" 或 "does" 中的"do" 。? 等價於 {0,1}。
{n} n 是一個非負整數。匹配肯定的 n 次。例如,'o{2}' 不能匹配 "Bob" 中的 'o',可是能匹配 "food" 中的兩個 o。
{n,} n 是一個非負整數。至少匹配n 次。例如,'o{2,}' 不能匹配 "Bob" 中的 'o',但能匹配 "foooood" 中的全部 o。'o{1,}' 等價於 'o+'。'o{0,}' 則等價於 'o*'。
{n,m} m 和 n 均爲非負整數,其中n <= m。最少匹配 n 次且最多匹配 m 次。例如,"o{1,3}" 將匹配 "fooooood" 中的前三個 o。'o{0,1}' 等價於 'o?'。請注意在逗號和兩個數之間不能有空格。
? 當該字符緊跟在任何一個其餘限制符 (*, +, ?, {n}, {n,}, {n,m}) 後面時,匹配模式是非貪婪的。非貪婪模式儘量少的匹配所搜索的字符串,而默認的貪婪模式則儘量多的匹配所搜索的字符串。例如,對於字符串 "oooo",'o+?' 將匹配單個 "o",而 'o+' 將匹配全部 'o'。
. 匹配除 "\n" 以外的任何單個字符。要匹配包括 '\n' 在內的任何字符,請使用象 '[.\n]' 的模式。
(pattern) 匹配 pattern 並獲取這一匹配。所獲取的匹配能夠從產生的 Matches 集合獲得,在VBScript 中使用 SubMatches 集合,在JScript 中則使用 $0…$9 屬性。要匹配圓括號字符,請使用 '\(' 或 '\)'。
(?:pattern) 匹配 pattern 但不獲取匹配結果,也就是說這是一個非獲取匹配,不進行存儲供之後使用。這在使用 "或" 字符 (|) 來組合一個模式的各個部分是頗有用。例如, 'industr(?:y|ies) 就是一個比 'industry|industries' 更簡略的表達式。
(?=pattern) 正向預查,在任何匹配 pattern 的字符串開始處匹配查找字符串。這是一個非獲取匹配,也就是說,該匹配不須要獲取供之後使用。例如,'Windows (?=95|98|NT|2000)' 能匹配 "Windows 2000" 中的 "Windows" ,但不能匹配 "Windows 3.1" 中的 "Windows"。預查不消耗字符,也就是說,在一個匹配發生後,在最後一次匹配以後當即開始下一次匹配的搜索,而不是從包含預查的字符以後開始。
(?!pattern) 負向預查,在任何不匹配 pattern 的字符串開始處匹配查找字符串。這是一個非獲取匹配,也就是說,該匹配不須要獲取供之後使用。例如'Windows (?!95|98|NT|2000)' 能匹配 "Windows 3.1" 中的 "Windows",但不能匹配 "Windows 2000" 中的 "Windows"。預查不消耗字符,也就是說,在一個匹配發生後,在最後一次匹配以後當即開始下一次匹配的搜索,而不是從包含預查的字符以後開始
x|y 匹配 x 或 y。例如,'z|food' 能匹配 "z" 或 "food"。'(z|f)ood' 則匹配 "zood" 或 "food"。
[xyz] 字符集合。匹配所包含的任意一個字符。例如, '[abc]' 能夠匹配 "plain" 中的 'a'。
[^xyz] 負值字符集合。匹配未包含的任意字符。例如, '[^abc]' 能夠匹配 "plain" 中的'p'。
[a-z] 字符範圍。匹配指定範圍內的任意字符。例如,'[a-z]' 能夠匹配 'a' 到 'z' 範圍內的任意小寫字母字符。
[^a-z] 負值字符範圍。匹配任何不在指定範圍內的任意字符。例如,'[^a-z]' 能夠匹配任何不在 'a' 到 'z' 範圍內的任意字符。
\b 匹配一個單詞邊界,也就是指單詞和空格間的位置。例如, 'er\b' 能夠匹配"never" 中的 'er',但不能匹配 "verb" 中的 'er'。
\B 匹配非單詞邊界。'er\B' 能匹配 "verb" 中的 'er',但不能匹配 "never" 中的 'er'。
\cx 匹配由 x 指明的控制字符。例如, \cM 匹配一個 Control-M 或回車符。x 的值必須爲 A-Z 或 a-z 之一。不然,將 c 視爲一個原義的 'c' 字符。
\d 匹配一個數字字符。等價於 [0-9]。
\D 匹配一個非數字字符。等價於 [^0-9]。
\f 匹配一個換頁符。等價於 \x0c 和 \cL。
\n 匹配一個換行符。等價於 \x0a 和 \cJ。
\r 匹配一個回車符。等價於 \x0d 和 \cM。
\s 匹配任何空白字符,包括空格、製表符、換頁符等等。等價於 [ \f\n\r\t\v]。
\S 匹配任何非空白字符。等價於 [^ \f\n\r\t\v]。
\t 匹配一個製表符。等價於 \x09 和 \cI。
\v 匹配一個垂直製表符。等價於 \x0b 和 \cK。
\w 匹配包括下劃線的任何單詞字符。等價於'[A-Za-z0-9_]'。
\W 匹配任何非單詞字符。等價於 '[^A-Za-z0-9_]'。
\xn 匹配 n,其中 n 爲十六進制轉義值。十六進制轉義值必須爲肯定的兩個數字長。例如,'\x41' 匹配 "A"。'\x041' 則等價於 '\x04' & "1"。正則表達式中可使用 ASCII 編碼。.
\num 匹配 num,其中 num 是一個正整數。對所獲取的匹配的引用。例如,'(.)\1' 匹配兩個連續的相同字符。
\n 標識一個八進制轉義值或一個向後引用。若是 \n 以前至少 n 個獲取的子表達式,則 n 爲向後引用。不然,若是 n 爲八進制數字 (0-7),則 n 爲一個八進制轉義值。
\nm 標識一個八進制轉義值或一個向後引用。若是 \nm 以前至少有 nm 個得到子表達式,則 nm 爲向後引用。若是 \nm 以前至少有 n 個獲取,則 n 爲一個後跟文字 m 的向後引用。若是前面的條件都不知足,若 n 和 m 均爲八進制數字 (0-7),則 \nm 將匹配八進制轉義值 nm。
\nml 若是 n 爲八進制數字 (0-3),且 m 和 l 均爲八進制數字 (0-7),則匹配八進制轉義值 nml。
\un 匹配 n,其中 n 是一個用四個十六進制數字表示的 Unicode 字符。例如, \u00A9 匹配版權符號 (?)。
例子
/\b([a-z]+)\b/i 單詞數量
/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/ 將一個URL解析爲協議、域、端口及相對路徑
/^(?:Chapter|Section) [1-9][0-9]{0,1}$/ 定位章節的位置
/[-a-z]/ A至z共26個字母再加一個-號。
/ter\b/ 可匹配chapter,而不能terminal
/\Bapt/ 可匹配chapter,而不能aptitude
/Windows(?=95 |98 |NT )/ 可匹配Windows95或Windows98或WindowsNT,當找到一個匹配後,從Windows後面開始進行下一次的檢索匹配。
^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$ Email 合法格式檢查
^[0-9]+$ 純數據檢查
^[0-9a-z]{1}[0-9a-z\-]{0,19}$ 用戶名檢查,字母和數字開始,只能含字母、數字、橫槓
模式修正符
i 忽略大小寫
s 若是設定了此修正符,模式中的圓點元字符(.)匹配全部的字符,包括換行符
e 只用在preg_replace(),在替換字符串中對逆向引用做正常的替換,將其做爲 PHP 代碼求值,並用其結果來替換所搜索的字符串。
如:
$p = '/\[colorFont\](.+?)\[\/colorFont\]/ie';
$t = '"<img src='color.php?t=".urlencode("\1")."\'/>"';
ecoh preg_replace($p,$t,$string);
這裏必須加上e修正,才能將匹配到的內容用urlencode處理
U 貪婪模式,最大限度匹配
如:/a[\w]+?e/U匹配abceadeddd中的abceade而不是abce,若是不加U修正,則匹配abce
A 強制從字符串開頭匹配,即自動在模式開頭加上^
m 當設定了此修正符,「行起始」 ^ 和「行結束」 $ 除了匹配整個字符串開頭和結束外,還分別匹配其中的換行符的以後和以前。若是目標字符串中沒有「\n」字符或者模式中沒有 ^ 或 $,則設定此修正符沒有任何效果。
D 模式中的美圓元字符僅匹配目標字符串的結尾。沒有此選項時,若是最後一個字符是換行符的話,美圓符號也會匹配此字符以前。若是設定了 m 修正符則忽略此選項
例子
匹配中文
preg_match_all('/[^\x00-\x80]+/', '中華s人s民', $a)
若是你的文件是gb2312的,用/[\xa0-\xff]{2}/
若是是utf8的,用/[\xe0-\xef][\x80-\xbf]{2}/
匹配郵箱地址
preg_match('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/', 'shao@gmail.com')
替換空白字符
$s = preg_replace('/[\s\v]+/','',' sss sdd ss ');
替換
$string = "April 15, 2003";
$pattern = "/(\w+) (\d+), (\d+)/i";
$replacement = "\${1}1,\${3}1-$2";
echo preg_replace($pattern, $replacement, $string);
匹配賬號是否合法(字母開頭,容許5-6字節,容許字母數字下劃線)
preg_match('/^[a-zA-Z][a-zA-Z0-9_]{4,5}$/', 'a011a')
匹配數字
/^-\d*$/ 匹配負整數
/^-?\d*$/ 匹配整數
匹配浮點數
preg_match("/^-?(\d*.\d*|0.\d*|0?.0+|0)$/", "11")
匹配電話號碼
preg_match("/^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7}){1,1}(\-[0-9]{1,4}){0,1}$/","0511-22345678-11")
匹配手機號碼
preg_match("/^1(3|5)\d{9}$/","13717897211")
文件處理
文件屬性
file_exists('1.php') 文件或目錄是否存在
filesize() 取得文件大小
is_readable() 判斷給定文件名是否可讀
is_writable() 判斷給定文件名是否可寫
is_executable() 判斷給定文件名是否可執行
filectime() 獲取文件的創造時間
filemtime() 獲取文件的修改時間
fileatime() 獲取文件的訪問時間
stat() 獲取文件大部分屬性值
解析目錄
basename() 返回路徑中的文件名部分
dirname() 返回目錄
pathinfo() 返回目錄名、基本名和擴展名的關聯數組
遍歷目錄
opendir() 打開指定目錄
readdir() 關閉指定目錄
closedir() 關閉指定目錄
rewinddir() 倒回目錄句柄
$dir_handle=opendir('.');
while($file=readdir($dir_handle))
{
echo filesize($file).'___'.$file.'<br>';
}
closedir($dir_handle);
創建和刪除目錄
mkdir() 建立目錄
rmdir() 刪除空目錄
文件操做
fopen()
fclose()
fwrite() 寫入文件
fputs() fwrite的別名
file_put_contents($文件名,$內容) 把內容存成文件
file_get_contents() 從文件讀出內容
文件讀取
fread()
stream_get_contents()
fgets() 從文件指針中讀取一行
feof() 測試文件指針是否到了文件結束的位置
fgetc() 從文件指針中讀取字符
file()
readfile() 讀入一個文件並寫入到輸出緩衝
ftell()返回文件指針的當前位置
fseek() 移動文件指針到指定的位置
rewind() 移動文件指針到文件的開頭
flock() 文件鎖定
copy() 複製文件
unlink() 刪除文件
ftruncate() 將文件截斷到指定的長度
rename() 重命名文件或目錄
文件控制
chgrp
chmod ( string $filename , int $mode )
chown
保存讀取文件
-----------把內容存成文件
$cache_file = fopen('f:\1.txt', 'w+');
fwrite($cache_file, $t);
-----------把內容存成文件
$s = "內容";
file_put_contents('f:/2.txt',$s);
-----------把文件內容讀成字符串
$s = file_get_contents('f:/2.txt');
echo $s;
-----------把文件內容按行讀成字符串
$handle = @fopen("f:/2.txt", "r");
if ($handle)
{
while (!feof($handle))
{
$buffer = fgets($handle, 4096);
echo $buffer.'<br>';
}
fclose($handle);
}
----------
session/cookie
setcookie("MyCookie[foo]", 'Testing 1', time()+3600)
session_start()
ini_set('session.cookie_lifetime',0); session對應cookie存活時間
ini_set('session.save_path', 'dir');
ini_set('session.save_path', '2;session');session分兩級存放
ini_set('session.name','SNS');
客戶端禁用Cookie
session.use_trans_sid = 1 開啓url傳遞sessionId php.ini
session銷燬
mysql
$link = mysql_connect('localhost','root','root') or die(mysql_errno());
mysql_select_db('test') or die (mysql_errno());
mysql_query('SET NAMES gbk');
$sql = "SELECT * FROM test LIMIT 0,20";
$result = mysql_query($sql) or die(mysql_errno());
while($msg = mysql_fetch_array($result)){
print_r($msg);
}
mysql_free_result($result);
mysql_close($link);
mysqli
查詢
-------------------------------過程
$db_host="localhost"; //鏈接的服務器地址
$db_user="root"; //鏈接數據庫的用戶名
$db_psw="root"; //鏈接數據庫的密碼
$db_name="test"; //鏈接的數據庫名稱
$mysqli=mysqli_connect($db_host,$db_user,$db_psw,$db_name);
mysqli_query($mysqli,'SET NAMES utf8');
$query="select * from users";
$result=mysqli_query($mysqli,$query);
while($row =mysqli_fetch_array($result)) //循環輸出結果集中的記錄
{
echo ($row['id'])."<br>";
echo ($row['username'])."<br>";
echo ($row['password'])."<br>";
echo "<hr>";
}
mysqli_free_result($result);
mysqli_close($mysqli);
-------------------------------對象
$db_host="localhost"; //鏈接的服務器地址
$db_user="root"; //鏈接數據庫的用戶名
$db_psw="root"; //鏈接數據庫的密碼
$db_name="test"; //鏈接的數據庫名稱
$mysqli=new mysqli($db_host,$db_user,$db_psw,$db_name);
$mysqli->query('SET NAMES utf8');
$query="select * from users";
$result=$mysqli->query($query);
if ($result)
{
if($result->num_rows>0) //判斷結果集中行的數目是否大於0
{
while($row =$result->fetch_array()) //循環輸出結果集中的記錄
{
echo ($row[0])."<br>";
echo ($row[1])."<br>";
echo ($row[2])."<br>";
echo "<hr>";
}
}
}
else
{
echo "查詢失敗";
}
$result->free();
$mysqli->close();
增、刪、改
$mysqli=new mysqli("localhost","root","root","sunyang");//實例化mysqli
$query="delete from employee where emp_id=2";
$result=$mysqli->query($query);
if ($result){
echo "刪除操做執行成功";
}else{
echo "刪除操做執行失敗";
}
$mysqli->close();
綁定結果
$mysqli=new mysqli("localhost","root","root","test"); //實例化mysqli
$query="select * from users";
$result=$mysqli->prepare($query); //進行預準備語句查詢
$result->execute(); //執行預準備語句
$result->bind_result($id,$username,$password); //綁定結果
while ($result->fetch()) {
echo $id.'_';
echo $username.'_';
echo $password;
echo "<br>";
}
$result->close(); //關閉預準備語句
$mysqli->close(); //關閉鏈接
綁定參數
$mysqli=new mysqli("localhost","root","root","test"); //實例化mysqli
$query="insert into users (id, username, password) values ('',?,?)";
$result=$mysqli->prepare($query);
$result->bind_param("ss",$username,$password); //綁定參數 I:integer D:double S:string B:blob
$username='sy0807';
$password='employee7';
$result->execute(); //執行預準備語句
$result->close();
$mysqli->close();
綁定參數、綁定結果
$mysqli=new mysqli("localhost","root","root","test"); //實例化mysqli
$query="select * from users where id < ?";
$result=$mysqli->prepare($query);
$result->bind_param("i",$id); //綁定參數
$id=10;
$result->execute();
$result->bind_result($id,$username,$password); //綁定結果
while ($result->fetch()) {
echo $id."_";
echo $username."_";
echo $password;
echo "<br>";
}
$result->close();
$mysqli->close();
多條查詢語句
$mysqli=new mysqli("localhost","root","root","test"); //實例化mysqli
$query = "select id from users ;";
$query .= "select id from test ";
if ($mysqli->multi_query($query)) { //執行多個查詢
do {
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
echo $row[0];
echo "<br>";
}
$result->close();
}
if ($mysqli->more_results()) {
echo ("-----------------<br>"); //連個查詢之間的分割線
}
} while ($mysqli->next_result());
}
$mysqli->close();//關閉鏈接
pdo
查詢
$db = new PDO('mysql:host=localhost;dbname=test', 'root', 'root');
$sql="SELECT * FROM users";
$result = $db->query($sql);
foreach ($result as $row)
{
var_dump($row);
}
$db = null;
增、刪、改、事務開啓
try
{
$db = new PDO('mysql:host=localhost;dbname=test', 'root', 'root');
$db->beginTransaction();
$a = $db->exec("insert into users (id, username, password) values ('', 'Joe', 'Bloggs')");
if($a == false)
{
throw new Exception("sql1執行失敗");
}
$b = $db->exec("insert into users (id, username, password,kkk) values ('', 'Joe', 'Bloggs')");
if($b == false)
{
throw new Exception("sql2執行失敗");
}
$db->commit();
$db = null;
}
catch (Exception $ex)
{
echo $ex;
$db->rollback();
}
緩存
Memcache
.下載memcached, http://www.danga.com/memcached/ ; 2.解壓,好比放在 D:\memcached-1.2.1 ; 3.DOS下輸入‘D:\memcached-1.2.1\memcached.exe -d install’,進行安裝(注意‘’不要輸入); 4.再次輸入‘D:\memcached-1.2.1\memcached.exe -d start’啓動memcached。 注意:memcached之後會隨機啓動。這樣memcached就已經安裝完畢了。
$memcache = new Memcache;
$memcache->addServer('172.19.5.199',11211);
$memcache->addServer('172.19.5.13',11211);
//$memcache->connect('localhost', 11211) or die ("Could not connect");
//$version = $memcache->getVersion();
//echo "Server's version: ".$version;
$memcache->set('key3',array(1,2,3));
var_dump($memcache->get('key3'));
ob
ob_start()
$content = ob_get_contents();
ob_clean();
$cache_file = fopen('f:\1.html', 'w+');
fwrite($cache_file, $content);
頁面靜態化--------------------------------------
ob_start();
$static_file = '1.html';//靜態頁面
$php_file = basename(__FILE__);//當前動態頁面
if (!file_exists($static_file) ||
((filemtime($static_file)+10) < time()) || //緩存固定時間
filemtime($php_file) > filemtime($static_file)) //源文件已修改
{
echo '靜態頁面示例';
echo 'erer';
$c = ob_get_contents();
ob_clean();
file_put_contents($static_file, $c);
}
$s = file_get_contents($static_file);
echo $s;
-------------------------------------------------
ob_implicit_flush($p) $p:0:關閉 1:開啓(每次輸出後都自動刷新,而再也不須要去調用flush())
ob_list_handlers 列出全部使用的輸出句柄
output_add_rewrite_var
output_add_rewrite_var('var', 'value');
echo '<a href="file.php">link</a>';
輸出:<a href="file.php?var=value">link</a>
output_reset_rewrite_vars
output_add_rewrite_var('var', 'value');
echo '<a href="file.php">link</a>';//輸出:<a href="file.php?var=value">link</a>
ob_flush();
output_reset_rewrite_vars();
echo '<a href="file.php">link</a>';//輸出:<a href="file.php">link</a>
僞靜態
首先:
必需要空間支持 Rewrite 以及對站點目錄中有 .htaccess 的文件解析,纔有效.
如何讓空間支持Rewrite 和 .htaccess 的文件解析呢 往下看
第一步:要找到apache安裝目錄下的httpd.cof文件,在裏面找到
<Directory />
Options FollowSymLinks
AllowOverride none
</Directory>
把none改all,
第二步:找到如下內容:
#LoadModule rewrite_module modules/mod_rewrite.so
改成
LoadModule rewrite_module modules/mod_rewrite.so
第三步:保存重啓apache。
ok。
其次是.htaccess的書寫規則:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#打開容許符號連接
Options FollowSymLinks
RewriteRule smarty/([0-9]+)/([0-9]+) smarty/index.php?id=$1&name=$2
</IfModule>
.htaccess加入如下內容
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)list-id([0-9]+)\.html$ $1/company/search.php?sectorid2=$2
RewriteRule ^(.*)cominfo-([a-z0-9]+)\.html$ $1/member/index.php?uid=$2&type=cominfo
RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/plus/list.php?typeid=$2&PageNo=$3
RewriteCond %{HTTP_HOST} ^[a-z0-9\-]+\.lujin\.com$
RewriteCond %{HTTP_HOST} !^(www|bbs)\.lujin\.com$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/([a-z0-9\-]+)\.lujin\.com/?$ /member/index.php?uid=$1 [L]
對上面的一些解釋
RewriteRule ^(.*)list-id([0-9]+)\.html$ $1/company/search.php?sectorid2=$2
這條是把企業庫的分類進行僞靜態處理
原先假設訪問地址爲http://www.xxx.com/company/search.php?sectorid2=1
如今地址爲http://www.xxx.com/list-id1.html
優勢:一、僞靜態處理加速搜索引擎收入
二、地址映射到根目錄,增長權重,提升排名
序列化
__sleep()
__wakeup()
-----------------
$a = array("1"=>"a","2"=>"b","3"=>"c","4"=>"d");
$b = serialize($a);/*序列化*/
var_dump($b);
$f = unserialize($b);/*解析*/
var_dump($f);
---------------------
class S
{
public $t = 111;
public function t()
{
echo 't function';
}
}
$s = new S;
$t = serialize($s);
$e = unserialize($t);
echo $e->t();
echo $e->t;
--------------------
class S
{
public $id;
public $name;
public function f()
{
echo 'f function';
}
function __sleep()
{
$this->id = uniqid();
return array('id','name');
}
function __wakeup()
{
//$this->id = uniqid();
}
}
$s = new S();
$s->name = 'name';
$e = serialize($s);
$t = unserialize($e);
echo $t->id.'_',$t->name,' ';
echo $t->f();
----------------------------
class S
{
public $t = 111;
public function t()
{
echo 't function';
}
}
$s = new S;
$t = serialize($s);
$cache_file = fopen('f:/1.txt', 'w+');
fwrite($cache_file, $t);
/*
die;
$e = unserialize($t);
echo $e->t();
echo $e->t;
*/
$handle = @fopen("f:/1.txt", "r");
if ($handle)
{
while (!feof($handle))
{
$buffer = fgets($handle, 4096);
break;
}
fclose($handle);
}
$e = unserialize($buffer);
echo $e->t();
echo $e->t;
-----------------------------------------
ThinkPHP2.0
入口文件配置
define('STRIP_RUNTIME_SPACE', false);生成的~runtime.php文件是否去空白和註釋
define('NO_CACHE_RUNTIME', true);不生成核心緩存文件
查詢
按照id排序顯示前6條記錄
$Form = M("Form");
$list = $Form->order('id desc')->limit(6)->select();
取得模板顯示變量的值
$this->assign('tt', 'vvvvvvvvvvvv');
echo $this->get('tt')
成功失敗提示頁
if(false !==$Form->add()) {
$this->success('數據添加成功!');
}else{
$this->error('數據寫入錯誤');
}
自動驗證
array(驗證字段,驗證規則,錯誤提示,驗證條件,附加規則,驗證時間)
驗證規則:require 字段必須、email 郵箱、url URL地址、currency 貨幣、number 數字
Model:: MODEL_INSERT 或者1新增數據時候驗證
Model:: MODEL_UPDATE 或者2編輯數據時候驗證
Model:: MODEL_BOTH 或者3 所有狀況下驗證(默認)
protected $_validate = array(
array('verify','require','驗證碼必須!'), //默認狀況下用正則進行驗證
array('name','','賬號名稱已經存在!',0,’unique’,1), // 在新增的時候驗證name字段是否惟一
array('value',array(1,2,3),'值的範圍不正確!',2,’in’), // 當值不爲空的時候判斷是否在一個範圍內
array('repassword','password','確認密碼不正確',0,’confirm’), // 驗證確認密碼是否和密碼一致
array('password','checkPwd','密碼格式不正確',0,’function’), // 自定義函數驗證密碼格式
);
apache多域名配置
NameVirtualHost *:80
Alias /php/ "f:/php/"
<Directory "f:/php/">
Options Indexes
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot F:/php
ServerPath F:/php
ServerAlias www.a.com
ServerName www.a.com
</VirtualHost>
<Directory "F:/php2">
Options Indexes
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName www.b.com
ServerAlias www.b.com
ServerPath F:/php2
DocumentRoot F:/php2
</VirtualHost>
PHP已經更新到不少個版本,最近用的比較多的要數PHP5。下面咱們爲你們總結了PHP5經常使用函數,以便你們未來實際編寫代碼中查看。 usleep() 函數延遲代碼執行若干微秒。 unpack() 函數從二進制字符串對數據進行解包。 uniqid() 函數基於以微秒計的當前時間,生成一個惟一的 ID。 time_sleep_until() 函數延遲代碼執行直到指定的時間。 PHP5經常使用函數之time_nanosleep() 函數延遲代碼執行若干秒和納秒。 sleep() 函數延遲代碼執行若干秒。 show_source() 函數對文件進行語法高亮顯示。 strip_whitespace() 函數返回已刪除 PHP 註釋以及空白字符的源代碼文件。 pack() 函數把數據裝入一個二進制字符串。 ignore_user_abort() 函數設置與客戶機斷開是否會終止腳本的執行。 highlight_string() 函數對字符串進行語法高亮顯示。 highlight_file() 函數對文件進行語法高亮顯示。 PHP5經常使用函數之get_browser() 函數返回用戶瀏覽器的性能。 exit() 函數輸出一條消息,並退出當前腳本。 eval() 函數把字符串按照 PHP 代碼來計算。 die() 函數輸出一條消息,並退出當前腳本。 defined() 函數檢查某常量是否存在。 define() 函數定義一個常量。 constant() 函數返回常量的值。 PHP5經常使用函數之connection_status() 函數返回當前的鏈接狀態。 connection_aborted() 函數檢查是否斷開客戶機。 zip_read() 函數讀取打開的 zip 檔案中的下一個文件。 zip_open() 函數打開 ZIP 文件以供讀取。 zip_entry_read() 函數從打開的 zip 檔案項目中獲取內容。 zip_entry_open() 函數打開一個 ZIP 檔案項目以供讀取。 PHP5經常使用函數之zip_entry_name() 函數返回 zip 檔案項目的名稱。 zip_entry_filesize() 函數返回 zip 檔案項目的原始大小(在壓縮以前)。 zip_entry_compressionmethod() 函數返回 zip 檔案項目的壓縮方法。 zip_entry_compressedsize() 函數返回 zip 檔案項目的壓縮文件尺寸。 zip_entry_close() 函數關閉由 zip_entry_open() 函數打開的 zip 檔案文件。 zip_close() 函數關閉由 zip_open() 函數打開的 zip 檔案文件。 xml_set_unparsed_entity_decl_handler() 函數規定在遇到沒法解析的實體名稱(NDATA)聲明時被調用的函數。 xml_set_processing_instruction_handler() 函數規定當解析器在 XML 文檔中找處處理指令時所調用的函數。 xml_set_object() 函數容許在對象中使用 XML 解析器。 PHP5經常使用函數之xml_set_notation_decl_handler() 函數規定當解析器在 XML 文檔中找到符號聲明時被調用的函數。 xml_set_external_entity_ref_handler() 函數規定當解析器在 XML 文檔中找到外部實體時被調用的函數。 xml_set_element_handler() 函數創建起始和終止元素處理器。 xml_set_default_handler() 函數爲 XML 解析器創建默認的數據處理器。 xml_set_character_data_handler() 函數創建字符數據處理器。 xml_parser_set_option() 函數爲 XML 解析器進行選項設置。 xml_parser_get_option() 函數從 XML 解析器獲取選項設置信息。 xml_parser_free() 函數釋放 XML 解析器。 PHP5經常使用函數之xml_parser_create() 函數建立 XML 解析器。 xml_parser_create_ns() 函數建立帶有命名空間支持的 XML 解析器。 xml_parse_into_struct() 函數把 XML 數據解析到數組中。 xml_parse() 函數解析 XML 文檔。 xml_get_error_code() 函數獲取 XML 解析器錯誤代碼。 xml_get_current_line_number() 函數獲取 XML 解析器的當前行號。 xml_get_current_column_number() 函數獲取 XML 解析器的當前列號。 PHP5經常使用函數之xml_get_current_byte_index() 函數獲取 XML 解析器的當前字節索引。 xml_error_string() 函數獲取 XML 解析器的錯誤描述。 utf8_encode() 函數把 ISO-8859-1 字符串編碼爲 UTF-8。 utf8_decode() 函數把 UTF-8 字符串解碼爲 ISO-8859-1。 wordwrap() 函數按照指定長度對字符串進行折行處理。 vsprintf() 函數把格式化字符串寫入變量中。 vprintf() 函數輸出格式化的字符串。 vfprintf() 函數把格式化的字符串寫到指定的輸出流。 PHP5經常使用函數之ucwords() 函數把字符串中每一個單詞的首字符轉換爲大寫。 ucfirst() 函數把字符串中的首字符轉換爲大寫。 trim() 函數從字符串的兩端刪除空白字符和其餘預約義字符。 substr_replace() 函數把字符串的一部分替換爲另外一個字符串。 substr_count() 函數計算子串在字符串中出現的次數。 substr_compare() 函數從指定的開始長度比較兩個字符串。 substr() 函數返回字符串的一部分。 strtr() 函數轉換字符串中特定的字符。 strtoupper() 函數把字符串轉換爲大寫。 strtolower() 函數把字符串轉換爲小寫。 PHP5經常使用函數之strtok() 函數把字符串分割爲更小的字符串。 strstr() 函數搜索一個字符串在另外一個字符串中的第一次出現。 strspn() 函數返回在字符串中包含的特定字符的數目。 strrpos() 函數查找字符串在另外一個字符串中最後一次出現的位置。 strripos() 函數查找字符串在另外一個字符串中最後一次出現的位置。 strrev() 函數反轉字符串。 strrchr() 函數查找字符串在另外一個字符串中最後一次出現的位置,並返回從該位置到字符串結尾的全部字符。 strpos() 函數返回字符串在另外一個字符串中第一次出現的位置。 PHP5經常使用函數之strpbrk() 函數在字符串中搜索指定字符中的任意一個。 strncmp() 函數比較兩個字符串。 strncasecmp() 函數比較兩個字符串。 strnatcmp() 函數使用一種「天然」算法來比較兩個字符串。 strnatcasecmp() 函數使用一種「天然」算法來比較兩個字符串。 strlen() 函數返回字符串的長度。 stristr() 函數查找字符串在另外一個字符串中第一次出現的位置。 stripos() 函數返回字符串在另外一個字符串中第一次出現的位置。 stripslashes() 函數刪除由 addslashes() 函數添加的反斜槓。 stripcslashes() 函數刪除由 addcslashes() 函數添加的反斜槓。 strip_tags() 函數剝去 HTML、XML 以及 PHP 的標籤。 strcspn() 函數返回在找到任何指定的字符以前,在字符串查找的字符數。 PHP5經常使用函數之strcoll() 函數比較兩個字符串。 strcmp() 函數比較兩個字符串。 strchr() 函數搜索一個字符串在另外一個字符串中的第一次出現。 strcasecmp() 函數比較兩個字符串。 str_word_count() 函數計算字符串中的單詞數。 str_split() 函數把字符串分割到數組中。 str_shuffle() 函數隨機地打亂字符串中的全部字符。 str_rot13() 函數對字符串執行 ROT13 編碼。 str_replace() 函數使用一個字符串替換字符串中的另外一些字符。 str_repeat() 函數把字符串重複指定的次數。 str_pad() 函數把字符串填充爲指定的長度。 str_ireplace() 函數使用一個字符串替換字符串中的另外一些字符。 PHP5經常使用函數之sscanf() 函數根據指定的格式解析來自一個字符串的輸入。 sprintf() 函數把格式化的字符串寫寫入一個變量中。 soundex() 函數計算字符串的 soundex 鍵。 similar_text() 函數計算兩個字符串的匹配字符的數目。 sha1_file() 函數計算文件的 SHA-1 散列。 sha1() 函數計算字符串的 SHA-1 散列。 setlocale() 函數設置地區信息(地域信息)。 PHP5經常使用函數之rtrim() P rtrim() 函數