简体   繁体   中英

Removing special keyboard characters/shapes with regex or?

I am using YQL to scrape some data, and then parsing it into Amazon's simpledb. I am getting some errors when attempting to insert certain titles into the DB, because some titles from the xml file that I am parsing contain characters like the one's below.

◆ ▒ ♠ ✖ ¸ . ´ ¨

I am sure that's not all the possible special characters. It's just the one's I've noticed so far that are causing the errors.

These are not standard keyboard characters. Is there a simple way to remove/disallow these types of characters (regex, etc..) without finding every one of them and including them in a regex?

Thanks

$text = preg_replace('/[^a-zA-Z0-9_ -]/s', '', $text);

This will trim your text so it only contains letters or numbers, spaces and underlines/dashes.

Reference http://www.phpfreaks.com/forums/index.php?topic=223131.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM