* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * This script "cleans" a MySpace blog feed by fixing unencoded and double * encoded entities, as well as converting "fancy" entities to plain text, where * "fancy" for the purposes of this script is basically any entities that * Facebook Notes doesn't like. * * It's a big hack. Suggestions welcome. * * @author Blaise Alleyne * @version 0.1 */ // Retrive the contents of the feed $feed = file_get_contents('http://blog.myspace.com/blog/rss.cfm?friendID=105852723'); // A list of tags to "clean" $tags = '(title|description|itunes\:author|itunes\:summary|itunes\:keywords|itunes\:name|itunes\:subtitle)'; // Clean up the HTML entities in the contents of these tags echo preg_replace_callback("/(<$tags>)([^<]+)(<\/$tags>)/", cleanEntities, $feed); /** * Undo double encoding, encode unencoded characters, convert any "fancy" * character entities to plain text, return the result. * * @param $match - the result returned from the regular expression * @return the tag with its "cleaned" contents **/ function cleanEntities($match){ $tag_open = $match[1]; $tag_close = $match[4]; // The contents of the tag $_0 = $match[3]; // Reverse any double encoding (e.g. &rsquo;) $_1 = html_entity_decode($_0, ENT_QUOTES, 'utf-8'); // Encode any unencoded characters (ignoring existing entities) $_2 = htmlentities($_1, ENT_QUOTES, 'utf-8', false); $contents = $_2; // Replace any "fancy" unicode character entities with plain text // Using list from: http://www.chuggnutt.com/html2text-source.php $contents = preg_replace('/&(quot|rdquo|ldquo|#8220|#8221|#147|#148);/i', '"', $contents); $contents = preg_replace('/&(apos|rsquo|lsquo|#8216|#8217);/i', "'", $contents); return $tag_open . $contents . $tag_close; } ?>