me1000 Posted December 27, 2006 Share Posted December 27, 2006 OK im working on a RSS feed and its pulling the feed content from my news database. most of the articles have special characters, like single and double quotes... Im currently using this code,[code]<?$q = preg_replace('/[^0-9a-z]/i','',$news_content);echo $q; ?>[/code]but I no longer get spaces!!!! Any help?Thanks, Quote Link to comment Share on other sites More sharing options...
corbin Posted December 27, 2006 Share Posted December 27, 2006 Wow, you could go really indepth with this, or you could not.The reason you arent getting spaces is because spaces arent 0-9 or a-z :p. I forgot how to represent space in regexp, but I'm sure someone will know...Thats also gonna replace things like !@#$%^&*().,/\=+-_~` and any other irregular characters... Quote Link to comment Share on other sites More sharing options...
me1000 Posted December 27, 2006 Author Share Posted December 27, 2006 Well anything thats not supported in an RSS feed needs to be gone. Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 27, 2006 Share Posted December 27, 2006 Using your code above, an encoded character in an RSS feed like & # 60; (without the spaces) would show up as the number 60 instead of the character '<'. I'm sure that's not what you intended. You can use html_entity_decode() and/or htmlspecialchars_decode() to handle some of the characters. The others, I would suggest a slight modification to your code where you define the special decimal character and it's replacement. Use arrays of the 'search for' and 'replace with' characters in the first two places of your preg_replace() statement. Quote Link to comment Share on other sites More sharing options...
me1000 Posted December 27, 2006 Author Share Posted December 27, 2006 The database doesn't hold any HTML in it at all, so basicly all i need is just to add spaces to my current code, so that it HAS spaces lol...Thanks! Quote Link to comment Share on other sites More sharing options...
alpine Posted December 27, 2006 Share Posted December 27, 2006 If you're still sticking with your original code, just add space as allowed and the spaces aren't removed:[code]$q = preg_replace('/[^ 0-9a-z]/i','',$news_content);[/code] Quote Link to comment Share on other sites More sharing options...
me1000 Posted December 27, 2006 Author Share Posted December 27, 2006 Thank You I really appreciate it! Quote Link to comment 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.