Reputation: 2770
I currently trying to do a str_replace in PHP which is new to me. Here is my current code.
$postAddress = str_replace("/current-url/", "/path/to/my-news/post/", $postAddress);
<li><a href="<?php echo $postAddress; ?>" ><?php echo $post->getTitle(); ?></a></li>
However in the above URL where I have 'my-news' I want to change that so it outputs the URL stored in the admin. So rather than doing an if statement for each category I want to output it as a variable.
Here is what i've tried to do:
$postAddress = str_replace("/current-url/", "/path/to/"echo $cat->getTitle() "/post/", $postAddress);
I hope this is enough info. Any help would be much appreciated.
Upvotes: 1
Views: 136
Reputation: 922
$postAddress = str_replace("/current-url/", "/path/to/" . $cat->getTitle() . "/post/", $postAddress);
Is that what you want? Use . for concatenation and don't echo the variable.
Upvotes: 1
Reputation: 1131
have a look at PHP String Operators.
$postAddress = str_replace("/current-url/", "/path/to/" . $cat->getTitle() . "/post/", $postAddress);
Upvotes: 4
Reputation: 1371
I think You have to do this:
$postAddress = str_replace("/current-url/", "/path/to/".$cat->getTitle()."/post/", $postAddress);
Upvotes: 4