Php 如何转换url字符串中的撇号或引号?

Php 如何转换url字符串中的撇号或引号?,php,character-encoding,special-characters,Php,Character Encoding,Special Characters,我正在尝试使用htmlspecialchars()或htmlspecialchars()转换URL字符串中的撇号。。。。但这对我不起作用 我有以下代码: <?php $new = htmlspecialchars("<a href='http://abc.test.net/content/22799-mdsap-partners-with-sap’s-‘moving-experience’-initiative-in-the-uae-and-oman'>Test</a&g

我正在尝试使用htmlspecialchars()或htmlspecialchars()转换URL字符串中的撇号。。。。但这对我不起作用

我有以下代码:

<?php
$new = htmlspecialchars("<a href='http://abc.test.net/content/22799-mdsap-partners-with-sap’s-‘moving-experience’-initiative-in-the-uae-and-oman'>Test</a>");
echo $new;
?>

但我从$new获得了输出:

<a href='http://abc.test.net/content/22799-mdsap-partners-with-sap’s-‘moving-experience’-initiative-in-the-uae-and-oman'>Test</a>


如何转换url中的撇号和单引号…

请尝试仅在您需要的部分使用urlencode(“您的url”)(否则会弄乱url的其余部分):

$new=”“;
echo$new;

将它们转换为什么?可能与-FYI重复,您的是“智能引号”的变体,如果您使用撇号,则在使用
htmlspecialchars
时使用
ENT\u quotes
标志。我想您可能需要URL编码,而不是HTML实体…
$new = "<a href='http://abc.test.net/content/" . urlencode("22799-mdsap-partners-with-sap’s-‘moving-experience’-initiative-in-the-uae-and-oman") . "'>Test</a>";
echo $new;