如何对php代码中的所有符号进行编码

How to uncode all symbole in the php code

我想在我的 php 代码中编码所有符号,如 à é è ...。示例:

à --> %C3%A0
é --> %C3%A9
è --> %C3%A8

我的代码中的示例:

$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . $Name . )

url需要这样:http://example.com/name/Te%C3%A0st
请问我需要在我的代码中添加什么?

您应该使用 urlencode 函数将字符转换为可在 URL 中使用的字符。

$Name = utf8_encode('Teàst');
$result = file_get_contents('http://example.com/name/' . urlencode($Name));

Update 正如您提到的编码是 ASCII 而不是 UFT-8 您需要先通过调用 utf8_encode 将编码从 ASCII 转换为 UFT-8,我已更新示例以显示这一点。