为什么php:preg_替换调用后丢失utf-8?

为什么php:preg_替换调用后丢失utf-8?,php,utf-8,Php,Utf 8,这是我的密码: $source = preg_replace('/<table align="center">(.*)<\/html>/s', '', $source ); file_put_contents('source1.html', $source); // source1 is GOOD : contains UTF-8 $source = preg_replace('/<html>.*<center>/sU', '', $sourc

这是我的密码:

$source = preg_replace('/<table  align="center">(.*)<\/html>/s', '', $source );
file_put_contents('source1.html', $source); // source1 is GOOD : contains UTF-8

$source = preg_replace('/<html>.*<center>/sU', '', $source );
file_put_contents('source2.html', $source); // source2 is BAD: contains some ðåùàéí
$source=preg_replace('/(.*)/s',''$source);
文件内容('source1.html',$source);//source1很好:包含UTF-8
$source=preg_replace('/.*/sU',''$source);
文件内容('source2.html',$source);//source2不好:包含一些
  • 第一个preg_替换保留utf-8字符(希伯来文字符)
  • 第二个preg_替换将所有这些字符替换为一些字符

有什么想法吗?

尝试使用
mb\u内部编码(“UTF-8”)

使用这种方法,我得到了一些����� 查理!这难道不是由给
preg_replace
的相同变量名引起的吗?然后将结果存储在哪里?我尝试了:$source2=preg_replace('/.*/sU','$source);文件内容('source2.html',$source2);//source2不好:包含一些