Question

Unsure of the correct syntax to add str_replace(' ', '_') to the below:-

<?php echo strtolower ($manufacturerName = $_product->getAttributeText('manufacturer')) ?>

Have tried all sorts of variations such as this:-

<?php echo strtolower (str_replace(' ', '_'), $manufacturerName = $_product->getAttributeText('manufacturer')) ?>

But nothing I've tried seems to be working because I'm not getting the syntax correct...

Perhaps preg_replace would even be better?

Was it helpful?

Solution

You have to move your ) more to the right.
The str_replace method takes 3 parameters (actually 4 but the forth is not important now).

You call it like str_replace(' ', '_').
I think you need this:

$manufacturerName = $_product->getAttributeText('manufacturer');
echo strtolower(str_replace(' ', '_', $manufacturerName));

OTHER TIPS

here is an example of STR_REPLACE function :

// Replacements order
$str     = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
$order   = array("\r\n", "\n", "\r");
$replace = '<br />';
$newstr = str_replace($order, $replace, $str);

I hope it'll helps
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top