PHPNewbie55 Posted September 17, 2007 Share Posted September 17, 2007 I am trying to get a DESCRIPTION for my RSS feed but there are too many special characters in the description for it to display properly. Is there any code that will replace everything?? I have tried:::: htmlentities() addslashes() htmlspecialchars() The problem is there are way too many special characters in my description to just replace each one of them... And not one of the above will do the job.... Stuff like:: ¼ — ö and a lot more.... I would just replace the ones I find as I go.. but that won't stop future descriptions from having more characters that I did not account for making my RSS feed messed up. Should I combine them all...?? htmlentities(htmlspecialchars(DESCRIPTION)); Or something like that...??? Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/ Share on other sites More sharing options...
darkfreaks Posted September 17, 2007 Share Posted September 17, 2007 also try using trim function and str_replace <?php $description= htmlentities(htmlspecialchars(trim($_POST[description])));?> Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-349971 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 Tried it... but it doesn't work.... ".htmlentities(htmlspecialchars(trim($data['DESCRIPTION'])))." Still too many special characters not accounted for with those functions.... Isn't there a function that will strip ALL special characters? Like I said if I try to replace them all it would be impossible to prevent future descriptions from containing what I had missed........ Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-349980 Share on other sites More sharing options...
rarebit Posted September 17, 2007 Share Posted September 17, 2007 Have a look at this... http://www.phpfreaks.com/forums/index.php/topic,159484.0.html and make your own lookup for ascii replacement, e.g. quarter = ¼ Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-349982 Share on other sites More sharing options...
darkfreaks Posted September 17, 2007 Share Posted September 17, 2007 <?php $description= mysql_real_escape_string(htmlentities(htmlspecialchars(trim($_POST[description]))));?> or you could do something like str_replace('@','') which would replace each character with nothing Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-349983 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 I tried this and it still doesn't do the job.... mysql_real_escape_string(htmlentities(htmlspecialchars(trim($_POST[description])))) So it looks like I'll just leave the description out of the feed then.... Because they use everything from foreign language characters to stuff I have never seen and it would take weeks to write a replacement for everything in these descriptions... (over 15,000 descriptions with tons of characters to replace) So there is no "SOLVED" for this one... since there doesn't seem to be a function that will replace everything but letters in the english alphabet... and the description doesn't look right with stuff like this in there for people to see.. ¼ Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-349999 Share on other sites More sharing options...
chocopi Posted September 17, 2007 Share Posted September 17, 2007 I guess you could take each word within the description and use some regex on it and then only return the word if its normal EDIT: You could then check each letter of the dodgy word and remove it if its bad, this would be sloppy but could work ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350001 Share on other sites More sharing options...
darkfreaks Posted September 17, 2007 Share Posted September 17, 2007 you should make a function like <?php function removspecchars($description) { str_replace('1/4',''); str_replace('ö',''); str_replace('_',''); }?> Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350003 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 darkfreaks.. Yes I could do that... but that means I would have a million replacements... and I would have to dig through 15,000 descriptions once a week in order to have them display properly... I am creating over 400 individual feeds.. and there would always be one character that messed up one of them... so it would be way too time consuming to monitor and keep up to date... I just thought that there would be a function that would replace everything in one shot... But it seems that there are not enough PREDEFINED characters in any replace function... So my best and easiest option would be to leave the description out of the feed all together... Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350014 Share on other sites More sharing options...
effigy Posted September 17, 2007 Share Posted September 17, 2007 I'm not sure that I understand. Are you trying to replace these characters with entities, or remove them altogether? If the feed is in UTF-8, make sure you decode it before passing it through these functions. Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350021 Share on other sites More sharing options...
darkfreaks Posted September 17, 2007 Share Posted September 17, 2007 he wants all special characters removed ??? Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350025 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 I am trying to remove them all... They are fine in PHP but in an XML feed they make the feed have errors and not display at all... Everything is fine in the XML feed until it finds a character that I cannot seem to replace or remove... Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350027 Share on other sites More sharing options...
darkfreaks Posted September 17, 2007 Share Posted September 17, 2007 you need to use preg_replace then Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350028 Share on other sites More sharing options...
$username Posted September 17, 2007 Share Posted September 17, 2007 ereg_replace("[^A-Za-z0-9.;:@]", "", any thing that is between [] will not be replaced. Hope this helps. Brett Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350030 Share on other sites More sharing options...
darkfreaks Posted September 17, 2007 Share Posted September 17, 2007 yeah preg_replace is the same thing but ereg_replace works as well Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350033 Share on other sites More sharing options...
effigy Posted September 17, 2007 Share Posted September 17, 2007 Removing characters would be avoiding the problem, rather than fixing it, correct? What character set is the feed in? I would assume UTF-8. Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350034 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 NEW to PHP so I have no idea what character set the feed is in.... BUT.... That DID Work perfectly.... I knew there had to be some way to do it.... Thanks for sticken with me on this one...!!!!!! GREATLY APPRECIATED....!! Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350039 Share on other sites More sharing options...
darkfreaks Posted September 17, 2007 Share Posted September 17, 2007 welcome hit topic solved Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350040 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 I don't want to avoid the problem so how would I find out what the character set is..?? NEW to PHP... so I don't know... Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350041 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 Now that the feed is displaying properly.. I am only going to include around 100 characters of the description so as long as the feed actually displays.. the users don't really need to see those special charcters any way... So... SOLVED!!! Thanks Again... When I learn more I'll participate and help others as well... Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350045 Share on other sites More sharing options...
effigy Posted September 17, 2007 Share Posted September 17, 2007 Are you creating the feed or only reading it? There should be a line at the top to indicate the encoding: <?xml version="1.0" encoding="utf-8"?> Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350048 Share on other sites More sharing options...
chocopi Posted September 17, 2007 Share Posted September 17, 2007 well just to improve on $username's code <?php $desc = // your rss stuff $desc = ereg_replace("[^ A-Za-z0-9.;:@?!\"£$%^&*()-_=+'<>/\\[\]\{\}]","",$desc); echo $desc; ?> I think thats all the basic keys on the standard english keyboard. ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350052 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 effigy I am creating the feeds and yes the first line is <?xml version="1.0" encoding="utf-8"?> I just didn't know where to look....... LOL... total noob... Chocopi Thanks for the "more info....." ----------- I did want to add that this place is a FREAKIN GOLD MINE of knowledge... For the past few months I have done nothing but read books and learn on my own... nice to have a place to ask questions I can't find the answers to..! Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350061 Share on other sites More sharing options...
effigy Posted September 17, 2007 Share Posted September 17, 2007 Where is the description coming from? A file, a database? Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350074 Share on other sites More sharing options...
PHPNewbie55 Posted September 17, 2007 Author Share Posted September 17, 2007 The description is coming from a MySQL Database.... Quote Link to comment https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/#findComment-350078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.