ibinod Posted July 13, 2009 Share Posted July 13, 2009 hi, how can i remove special characters like �♪♫ i tried htmlentities, htmlspecialchars but i can't fix it, pls let me know how Quote Link to comment https://forums.phpfreaks.com/topic/165755-removing-special-characters/ Share on other sites More sharing options...
RussellReal Posted July 13, 2009 Share Posted July 13, 2009 so what characters do you want to keep? a-z, 0-9, !@#$%^&*() ;'.,[]{}":><|\~` ? a-z A-Z 0-9 all those symbols.. they are usually in succession, find out what their ascii values are and loop thru the text and remove anything thats not between those.. if you don't understand what I mean I'll help you out some more Quote Link to comment https://forums.phpfreaks.com/topic/165755-removing-special-characters/#findComment-874346 Share on other sites More sharing options...
ibinod Posted July 13, 2009 Author Share Posted July 13, 2009 Hello RussellReal, actually i m making a script to get news content from yahoo rss and along with it i am getting characters like those �♪♫ and making XHTML invalid, so what's the best way to remove those and similar chars and how do i loop through text to remove those, thanx Quote Link to comment https://forums.phpfreaks.com/topic/165755-removing-special-characters/#findComment-874350 Share on other sites More sharing options...
RussellReal Posted July 13, 2009 Share Posted July 13, 2009 Post some of your code.. where you handle the data you receive.. and I'll help you patch it in there Quote Link to comment https://forums.phpfreaks.com/topic/165755-removing-special-characters/#findComment-874353 Share on other sites More sharing options...
ibinod Posted July 13, 2009 Author Share Posted July 13, 2009 //i have some text in the database like this $string = " �Public Enemy Number One� has long interested people who have then journeyed to visit his last resting place; ♪♫ Zac Efron & Jessica Alba WIN '07 Teen Choice Hottie Award"; // i have this function to remove un necessory tags (actually those are for urls) function sef_rep($name) { $name = html_entity_decode(strtolower($name)); $remove = array("/", "'", "`", "!", "(", ")", ".", "@", "+", " ", "_", "<", ">", "?", ":", ";", "&", "#", ","); $result_str = str_replace($remove, '-', $name); return $result_str; } //so when i echo this those special characters haven't gone echo sef_rep($string); so pls post me a solution to remove special chars like � Quote Link to comment https://forums.phpfreaks.com/topic/165755-removing-special-characters/#findComment-874358 Share on other sites More sharing options...
RussellReal Posted July 13, 2009 Share Posted July 13, 2009 <?php function sef_rep($name) { $name = html_entity_decode(strtolower($name)); $r = range(33,126); $remove = array("/", "'", "`", "!", "(", ")", ".", "@", "+", " ", "_", "<", ">", "?", ":", ";", "&", "#", ","); $name = str_replace($remove, '-', $name); $l = strlen($name); for ($i = 0; $i < $l; $i++) { $c = ord(substr($name,$i,0)); if (!in_array($c,$r)) { $name = substr($name,0,$i - 1).substr($name,$i + 1,$l - ($i + 1)); $i--; } } return $name; } ?> try that Quote Link to comment https://forums.phpfreaks.com/topic/165755-removing-special-characters/#findComment-874363 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.