eevan79 Posted July 21, 2010 Share Posted July 21, 2010 I am using syntax highlighter to highlight code between tags. Here is bbcode: [b]search:[/b] [code=php:0]'/\[code\]([\s\S]*?)\[\/code\]/si' replace: '<pre><code>$1</code></pre> ' And its working fine. Now I want to reverse code (for example. when user edit post). So I use: '/<pre\s[^<>]*?code\"?[^<>]*?>([^<>]*?)<\/pre>/si' to: '[code ]$1[/code ]' But its not working. 1. How to properly reverse this regex? Also when I put code between [ code]and[/code ] tags I get lots of empty spaces. For example here is source from phpmyadmin: <pre><code>require_once 'Zend/Uri/Exception.php'; <br>require_once 'Zend/Uri/Http.php'; <br>require_once 'Zend/Uri/Mailto.php'; <br> <br>abstract class Zend_Uri <br>{ <br> <br> /** <br> * Return a string representation of this URI. <br> * <br> * @see getUri() <br> * @return string <br> */ <br> public function __toString() <br> { <br> return $this->getUri(); <br> } <br> <br> static public function factory($uri = 'http') <br> { <br> $uri = explode(':', $uri, 2); <br> $scheme = strtolower($uri[0]); <br> $schemeSpecific = isset($uri[1]) ? $uri[1] : ''; <br> <br> // Security check: $scheme is used to load a class file, <br> // so only alphanumerics are allowed. <br> if (!ctype_alnum($scheme)) { <br> throw new Zend_Uri_Exception('Illegal scheme'); <br> } <br> } <br>} <br>array("\r\n", "'", '"', '&', '$', '<', '>'), $text)); <br>?></code></pre> There are lots of <br>. 2. Can I remove double <br> when text is between [color=red] tags?[/color] Quote Link to comment Share on other sites More sharing options...
soycharliente Posted July 25, 2010 Share Posted July 25, 2010 Would str_replace be easier? 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.