How to remove string in url with preg_replace



I’m trying to remove “amp/” for my url.

I have code like this:

<?php echo Mage::helper('core/url')->getCurrentUrl(); ?>

It outputs like this:

I’ve been trying but so far everything I’ve tried gives me an error:

<?php $str = Mage::helper('core/url')->getCurrentUrl()); ?><?php echo preg_replace('amp', "", $str); ?>

Can someone show how to do this?
Thank you


Why not use str_replace?

1 Like

You need to put delimiters either side of your search pattern.
But I agree with @gandalf458 preg_replace is overkill for a simple replace of a known string, keep it simple and use str_replace.


Thanks, I changed it to this:

<?php $str = Mage::helper('core/url')->getCurrentUrl(); ?><?php echo str_replace("amp/","","$str"); ?>

and it works.

1 Like

Try this:

$str = Mage::helper('core/url')->getCurrentUrl(); 
echo str_replace("amp/",'',$str);