preg_replace
字串比對解析並取代。
語法:mixedpreg_replace(mixedpattern,mixedreplacement,mixedsubject);
返回值:混合型別資料
函式種類:資料處理
內容說明
本函式以pattern的規則來解析比對字串subject,欲取而代之的字串為引數replacement。返回值為混合型別資料,為取代後的字串結果。
使用範例
下例返回值為$startDate=6/19/1969
複製程式碼 程式碼如下:
<?php
$patterns=array("/(19|20d{2})-(d{1,2})-(d{1,2})/","/^s*{(w+)}s*=/");
$replace=array("3/4/1","$1=");
printpreg_replace($patterns,$replace,"{startDate}=1969-6-19");
?>