doumen6605 2018-12-02 05:21
浏览 51

Img在字符串编码后将请求结果发送到utf-8

Sorry If I'm doing a duplicate, but I couldn't find the exact solution to my problem. Since I need my page to be displayed in utf-8, I'm currently reading a file into string using a function that I found, and decoding it:

function file_get_contents_utf8($fn) {
 $content = file_get_contents($fn);
  return mb_convert_encoding($content, 'UTF-8',
      mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));}

After that, I'm echoing that string in my .php file in order to represent the content in my web-page. However, some img tags src parameters have special characters and where I should have a %F3 character results in a %C3%B3, what consequently will cause a 404 error. My questions:
Is there any easy way of getting all my string img src parameters and replace them with the correspondent urlencode?
Am I using the best approach to solve my problem?

Example: After encoding my string where i should have:

<img src="https://path/to/file/Convite%20Lan%E7amento%20do%20livro%20Eletr%F3nica.jpg">

I get:

<img src="https://path/to/file/Convite%20Lan%C3%A7amento%20do%20livro%20Eletr%C3%B3nica.jpg">

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗