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" /> Link to comment https://forums.phpfreaks.com/topic/58285-search-and-replace-with-regular-expressions/ 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> Link to comment https://forums.phpfreaks.com/topic/58285-search-and-replace-with-regular-expressions/#findComment-289016 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 Link to comment https://forums.phpfreaks.com/topic/58285-search-and-replace-with-regular-expressions/#findComment-289032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.