gpt4 book ai didi

php - file_get_contents 将所有特殊字符转换为菱形问号 php

转载 作者:行者123 更新时间:2023-11-28 02:33:58 25 4
gpt4 key购买 nike

我正在我的项目中上传一个 html 文档并使用 file_get_contents() 检索文件内容。

但每次出现一些引号或任何特殊字符时,它都会被转换为菱形问号。

下面是我的代码

    **$path = public_path().'/upload/'.$filename.'.'.$extension;
$striped_content = file_get_contents($path);**

striped_content 的输出如下

<p class=MsoNormal align=right style='margin-top:0cm;margin-right:2.1pt;
margin-bottom:0cm;margin-left:0cm;margin-bottom:.0001pt;text-align:right;
line-height:10.8pt;mso-line-height-rule:exactly'><u style='text-underline:black'>
<span lang=EN-US style='font-size:9.5pt;font-family:"Times New Roman","serif";
mso-fareast-font-family:"Times New Roman";position:relative;top:.5pt;
mso-text-raise:-.5pt'>
<span style='mso-spacerun:yes'>�</span>
</span>
</p>

上面的代码是简单的 html,由引号组成,但它显示的是问号。我现在该怎么办。

最佳答案

The Character displayed in black diamond question mark are treated as ISO-8859-1 unicode and we are converting it into utf-8.
Below Is my Code That worked Perfectly

$path = public_path().'/upload/'.$filename.'.'.$extension;
$striped_content = file_get_contents($path);
$striped_content = mb_convert_encoding($striped_content, 'HTML-ENTITIES', "ISO-8859-1");

我希望我的回答对其他人也有帮助。

关于php - file_get_contents 将所有特殊字符转换为菱形问号 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48581232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com