Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.