2013-10-04 395 views
0

PHP更新後,5.4.19面臨一個以前不存在的新警告。它說:Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in ... on line 645如何解決preg_replace警告?

有一種方法:

private function BBtoHTML($input_string) 
{ 
    $search = array(
     '/\[b\](.*?)\[\/b\]/is', 
     '/\[i\](.*?)\[\/i\]/is', 
     '/\[u\](.*?)\[\/u\]/is', 
     '/\[s\](.*?)\[\/s\]/is', 
     '/\[quote\](.*?)\[\/quote\]/is', 
     '/\[code\](.*?)\[\/code\]/is', 
     '/\[url\=(.*?)\](.*?)\[\/url\]/is', 
     '/\[(left|center|right)\](.*?)\[\/(left|center|right)\]/is', 
     '/\[font\=(.*?)\](.*?)\[\/font\]/is', 
     '/\[size\=(.*?)\](.*?)\[\/size\]/is', 
     '/\[color\=(.*?)\](.*?)\[\/color\]/is', 
     '\{PAGEBREAK\}', 
    ); 

    $replace = array(
     '/<strong>$1</strong>/', 
     '/<em>$1</em>/', 
     '/<span style="text-decoration: underline;">$1</span>/', 
     '/<del>$1</del>/', 
     '/<blockquote>$1</blockquote>/', 
     '/<code>$1</code>/', 
     '/<a href="$1" target="_blank">$2</a>/', 
     '/<div style="text-align: $1;">$2</div>/', 
     '/<span style="font-family: $1;">$2</span>/', 
     '/<span style="font-size: $1;">$2</span>/', 
     '/<span style="color: $1;">$2</span>/', 
     '/<!--nextpage-->/' 
    ); 

    return preg_replace($search, $replace, $input_string); 
} 

正如你可能在645明白是return preg_replace($search, $replace, $input_string)

回答

1

你擁有的最後一個模式是'\{PAGEBREAK\}'。如果你的意思是匹配字面\{PAGEBREAK\}用反斜槓包括模式應該是:

 '/\\\\{PAGEBREAK\\\\}/', 

如果你的意思是匹配{PAGEBREAK}模式應該是:

 '/{PAGEBREAK}/',