程式

<?
$str = "This is the [*worst*] day [*of*] my life.";
preg_match_all("[*([^*]+)*]", $str, $out, PREG_PATTERN_ORDER);

echo "str = '$str' <br>"; 
echo "<pre>" . print_r($out, true) . "</pre>";
?>



錯誤訊息
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in D:\TMS\www_test\index.php on line 3

原因

ereg 系列的function pattern 參數前後不需要加上 /
而 preg 系列的 function 卻要加

解法
所以第三行改為
preg_match_all("/[*([^*]+)*]/", $str, $out, PREG_PATTERN_ORDER);
就可以了




創作者介紹
創作者 長島冰茶的工程師筆記 的頭像
wbkuo

長島冰茶的工程師筆記

wbkuo 發表在 痞客邦 留言(0) 人氣( 189 )