I'm using PHP smarty to declare a link :
<{foreach item=list key=num from=$product}>
<li><a href="<{$config.weburl}>/<{$list.somename}>"><{$list.somename}></a></li>
<{/foreach}>`
and the resulting link when mouseover is :
"http:/domain/some name"
I need to str_replace the space char (some name) with an underscore (some_name), how to do that?? like result below :
"http:/domain/some_name"
I'm using the following code but it does not work. How to use str_replace with an array in html?
<a href="<{$config.weburl}>/'.str_replace(array(' ','%'),array('_','-'),<{$list.somename}>).'">
You can use PHP functions as Smarty modifiers, but Smarty has a built-in replace
modifier. Use it like this:
<{foreach item=list key=num from=$product}>
<li><a href="<{$config.weburl}>/<{$list.somename|replace:' ':'_'}>"><{$list.somename}></a></li>
<{/foreach}>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With