Sinz
August 4, 2010, 11:52pm
1
Hello all
I have a CMS script, but I’m running into some issues
When ever I create a post that contains $ - or . % and some other ones…
on the front page the URL is displaying those characters is there any way to strip those characters?
this is the code I’m currently using and it is only removing the "& "
<?php echo str_ireplace("&","",str_ireplace(" ","-",html_entity_decode($row['title']))); ?>.html"><?php echo str_ireplace("-"," ",$row['title']); ?>
any help ? thanks!
Sinz
September 19, 2010, 8:43pm
2
rpkamp:
So if I’m getting this correct you don’t want to rewrite the & character?
In that case the line would be
<a href="http://www.xxxx.com/<?=str_ireplace(array("-",".","%"," "),"-",html_entity_decode($row['genre']));?>/<?=str_ireplace(array("-",".","%"," "),"-",html_entity_decode($row['name']));?>.html"><?=html_entity_decode($row['name']);?></a>
I tried that and it does remove the characters but now the URL is displayed like: http://www.xxxx.com/Free-shipping-and-20--off
after the 20 it is placing and an extra -
thanks
(the original entry to the db is Free shipping and 20% off)
Sinz
August 5, 2010, 1:50am
3
Thank you very much! that worked like a charm
I have one more request however if you can help me out one more time
It is similar problem I’m facing in this part of the script, as the one I mentioned above here is the code:
<?php while($row=mysql_fetch_assoc($getNews)){ ?>
<div class="homeres">
<div class="doscol">
<a href="http://www.xxxx.com/<?=str_ireplace(" ","-",html_entity_decode($row['genre']));?>/<?=str_ireplace(" ","-",html_entity_decode($row['name']));?>.html"><?=html_entity_decode($row['name']);?></a>
<?php $i++; }?>
rpkamp
August 5, 2010, 12:47am
4
Replace
str_ireplace("&","", ...
with
str_ireplace(array("&","-",".","%"),"", ...
(expand as needed)
rpkamp
August 5, 2010, 11:12am
5
I thought that is what you wanted? Please explain in more detail what you’re trying to achieve
Sinz
August 5, 2010, 11:08am
6
I tried the above but what is happening now is it is removing “&” but it is placing a dash (-) where the & used to be and the link is not working
is this somehow problem with my .htaccess ?
thanks
rpkamp
August 5, 2010, 8:11pm
7
So if I’m getting this correct you don’t want to rewrite the & character?
In that case the line would be
<a href="http://www.xxxx.com/<?=str_ireplace(array("-",".","%"," "),"-",html_entity_decode($row['genre']));?>/<?=str_ireplace(array("-",".","%"," "),"-",html_entity_decode($row['name']));?>.html"><?=html_entity_decode($row['name']);?></a>
rpkamp
August 5, 2010, 8:48am
8
<?php while($row=mysql_fetch_assoc($getNews)){ ?>
<div class="homeres">
<div class="doscol">
<a href="http://www.xxxx.com/<?=str_ireplace(array("&","-",".","%"," "),"-",html_entity_decode($row['genre']));?>/<?=str_ireplace(array("&","-",".","%"," "),"-",html_entity_decode($row['name']));?>.html"><?=html_entity_decode($row['name']);?></a>
<?php $i++; }?>
Since the code you posted replaced spaces, I added that to the list of characters to be replaced as well
Sinz
August 5, 2010, 7:48pm
9
The issue with the characters is that they are all links: so when you click on one it sends you to the actual news story etc…
so when I tried the code you posted it is removing the & but now the link looks like this (example) "buy-roses-for-only–25-dollars " and when I click on it, won’t go to the actual item
I think the issue is the added - before the 25 or something conflicting with my htaccess?