// 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
// 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