preg_replace_callback();
无法在NGINX服务器上运行,但它正在本地Apache服务器上运行。
我认为这不是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 example@example.com and my second is example1@example.com';
$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]) .'">';
}
?>
答案 0 :(得分:0)
进行如下更改:
$text = 'my email is example@example.com and my second is example1@example.com';
$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])?/';
$html = preg_replace_callback($email_pattern, function ($matches){
return '<img src="image.php?id='. base64_encode($matches[0]) .'">';
}, $text );
echo $html;
我希望它能奏效。