Remove special characters from php result

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!

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)

Thank you very much! that worked like a charm

I have one more request however if you can help me out one more time :slight_smile:

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++;	}?>																

Replace


str_ireplace("&","", ...

with


str_ireplace(array("&","-",".","%"),"", ...

(expand as needed)

:slight_smile:

I thought that is what you wanted? Please explain in more detail what you’re trying to achieve :slight_smile:

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

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>

:slight_smile:

				<?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 :slight_smile:

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?