marm Posted July 3, 2007 Share Posted July 3, 2007 How could I replace all the commas with "commas followed by a space" only within the keywords meta tag ? (using dreamweaver's regular expressions) Turn this: <meta name="Keywords" content="word1,word2,word3,word4,word5,word6" /> into this: <meta name="Keywords" content="word1, word2, word3, word4, word5, word6" /> Quote Link to comment Share on other sites More sharing options...
effigy Posted July 3, 2007 Share Posted July 3, 2007 Here's PHP, but I realized you want to do this within Dreamweaver, which I've no idea of (and doubt that it can). Let me know if I need to move this to another forum. Sorry about that. <pre> <?php $html = <<<HTML <meta name="Keywords" content="word1,word2,word3,word4,word5,word6" /> <meta name="NotKeywords" content="word1,word2,word3,word4,word5,word6" /> HTML; function commafy_keywords ($match) { if ($match[0] = preg_split('/(content=")([^"]+)(")/', $match[0], -1, PREG_SPLIT_DELIM_CAPTURE)) { $match[0][2] = preg_replace('/(?<=,)(?! )/', ' ', $match[0][2]); } return implode('', $match[0]); } echo htmlspecialchars(preg_replace_callback('/<meta[^>]+name="Keywords"[^>]*>/', 'commafy_keywords', $html)); ?> </pre> Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 3, 2007 Share Posted July 3, 2007 http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions_03.html 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.