John Brown
John Brown

Reputation: 39

php echo the link, but replace some url string , how?

I have this link :
<a href="<?php echo Mage::getURL() ?>brands/<?php echo $_brand['label'] ?>">
This will give me a result of
brands/Example%20Of%20My%20Brand in the url and is not good,because it is 404.
The actual name of the brand is "Example Of My Brand" and the URL to reach this page "example-of-my-brand" so this is what i need to get
What I need to do is trim/replace? the %20 so it will be "-" and also if it is possible to make all the link lowercase?
Thank you very much, I hope somebody can help.

Upvotes: 0

Views: 791

Answers (5)

Thirumalai murugan
Thirumalai murugan

Reputation: 5896

Actually %20 is space you try this

 <a href="<?php echo Mage::getURL() ?>brands/<?php echo str_replace(' ','-',$_brand['label']) ?>">

Check this for lower case

<?php 
  $link=Mage::getURL().'brands/'.str_replace(' ','-',$_brand['label']);
  $link=strtolower($link); 
?>

<a href="<?php echo $link;?>">

Upvotes: 1

Naryl
Naryl

Reputation: 1888

<?php
$part1=Mage::getURL();
$part2=str_replace(" ", "-", urldecode($_brand['label']));
$newurl=strtolower($part1."brands/".$part2);
?>

<a href="<?php echo $newurl ?>">

Something like this should work.

If $part1 has any url-encoded character just use urldecode on it as well.

Upvotes: 2

anubhava
anubhava

Reputation: 784998

As per getUrl documentation, I think you should be using:

$url = Mage::getUrl('', array('_use_rewrite' => true)); 

_use_rewrite => Looks up the module/controller/action/parameters in the database for a search engine friendly equivalent.

Upvotes: 0

CoursesWeb
CoursesWeb

Reputation: 4237

Use str_replace().

<a href="<php echo strtolower(str_replace('%20', '-', Mage::getURL().'brands/'.$_brand['label'])); ?>">

Upvotes: 0

thumber nirmal
thumber nirmal

Reputation: 1617

first of all concat all this variable and string and then add this in href like this

 <?php    $abc = Mage::getURL();
$final =$abc.'brands'.$brand['label'];?>
 <a href="<?php echo $final?>">

Upvotes: 0

Related Questions