-2

I am trying to convert the apostrophe in URL string using htmlentities() or htmlspecialchars() .... but it is not working for me...

I have following code:

<?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;
?>

but I am getting the output from $new:

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

How to convert the apostrophe and single quotes in url...

  • 1
    Convert them into _what_? – misorude Aug 29 '19 at 11:01
  • Possible duplicate of [Convert all types of smart quotes with PHP](https://stackoverflow.com/questions/20025030/convert-all-types-of-smart-quotes-with-php) - FYI, yours are a variant of the "smart quotes" and if you do make them apostrophes then use the `ENT_QUOTES` flag when using `htmlspecialchars`. – Script47 Aug 29 '19 at 11:01
  • I think you might want URL encoding, not HTML entities … – misorude Aug 29 '19 at 11:01

1 Answers1

1

Try to use urlencode("your URL") only on the part you need (otherwise it will mess up the rest of the URL):

$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;