Jump to content

<pre><code> to [code]


eevan79

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/208466-to-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.