PHP Replace “&” With “%26” in URL encoding ampersands

// replace & to %26
$string = “M&M”;
$string = str_replace(“&”, urlencode(“&”), html_entity_decode($string));
//————————————–

OUTPUT on url will be M%26M
OUTPUT on your page still M&M

Leave a Reply

Your email address will not be published. Required fields are marked *