Why does this preg_replace function not work?

From: Date: Fri, 26 May 2006 09:26:04 +0000
Subject: Why does this preg_replace function not work?
Groups: php.general 
Request: Send a blank email to php-general+get-236931@lists.php.net to get a copy of this message
PHP List, In the code below, I want to take the text within $content, and change every instance of [h3] into <h3>, and every instance of [/h3] into </h3>. And then do the same for [em], [/em], [strong], and so on. However, this code does absolutely nothing to the text stored in content: $tags = array ("h3", "em", "strong", "hr"); $content = preg_replace("[" . $tags . "]", "<" . $tags . ">", $content); $content = preg_replace("[/" . $tags . "]", "</" . $tags . ">", $content); Clearly I've either misunderstood the use of preg_replace(), or regular expressions, or arrays, despite having looked them up in the PHP online manual. I also tried str_replace(), but predictably that did not help. As far as I understand it, it does not accept arrays. What am I doing wrong in the above code? And can the two preg_replace() commands be achieved in one line? Thank you for any advice. -- Dave M G

« previous php.general (#236931) next »