Hi,
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:
https://www.example.com/amp/
https://www.example.com/amp/some-url.html
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
You need to put delimiters either side of your search pattern.
But I agree with @Gandalf 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
Freejoy:
<?php $str = Mage::helper('core/url')->getCurrentUrl(); ?><?php echo str_replace("amp/","","$str"); ?>
Try this:
<?php
$str = Mage::helper('core/url')->getCurrentUrl();
echo str_replace("amp/",'',$str);
?>
system
Closed
August 24, 2019, 6:22am
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.