1
preg_replace_callback();
不能在NGINX服務器上工作,但它在本地Apache服務器上工作。preg_replace_callback在服務器上不工作
,我想是不是在Apache/NGINX的錯誤,
,我將所有的電子郵件從字符串到圖像,但它的顯示如下一些錯誤。
Warning: preg_replace_callback(): Requires argument 2, 'encode_email', to be a valid callback in /home/abc/public_html/test.php on line 170
你可以看到我的代碼是在這裏:
<?php
$email_pattern = '/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/';
$text = 'my email is [email protected] and my second is [email protected]';
$html = preg_replace_callback($email_pattern, "encode_email", "$text");
echo $html;
function encode_email($matches){
return '<img src="image.php?id='. base64_encode($matches[0]) .'">';
}
?>
這不太可能與nginx/apache的區別有關。這可能是兩個系統上的PHP版本之間的差異嗎? – Simba
@Simba你可能是對的,但兩個服務器都有相同的PHP版本,但我認爲這是一些邏輯或語法錯誤 –
你確定你不想使用'preg_replace()'?! – Rizier123