Feb 26, 2010
Magic HTML Machine
At my current job, I am a web producer so there’s a lot of formatting articles and then shoving them into a CMS. For the first few weeks of working here, I used to do it manually… one at a time. Then I started using Dreamweaver to do it with the ctrl+shift+p shortcut. One day sitting at home, I created a “tool” to do it for me with some simple regular expressions:
$edit = str_replace("\r\n\r\n","</p><p>",$text);
This was all fine and dandy for me but when you work with a company where some people like to copy and paste from MS Word, curly quotes can be an issue. I had opened my tool to a few coworkers initially and after curly quotes were an often enough problem, I implemented a search and replace for that while p tagging the content:
function convert_smart_quotes($string) { $search = array(chr(145), chr(146), chr(147), chr(148), chr(151)); $replace = array("'", "'", '"', '"', '-'); return str_replace($search, $replace, $string); } $text = convert_smart_quotes(htmlentities($_POST['text']));
Here is the finish product, not fancy or decorated at all since it’s just a tool for convenience.