SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get the code inside the preg_replaces?

    Code PHP:
    	private static function CodeTag($string) {
     
    		$str = str_replace("]\n", "]", $string);
    		$match = array('#\[code\](.*?)\[\/code\]#se');
    		$replace = array("'<div class=\"php_tag\">'.highlight_string(stripslashes('$1'), true).'</div>'");
    		$result = preg_replace($match, $replace, $str);
    		return $result;
    		#$result	= explode("<br />", $result);
    		#$return = NULL;
    		#$x = 1;
    		#	foreach ($result as $line => $syntax) {
    		#		$return .= "<font color='black'>".$x."</font> ".$syntax."<br>";
    		#		$x++;
    		#	}
    
    		#return $return;
    	}

    Essentially what I want todo is get the code inside the [code] tags to use the highlight_string, but as you can see here: http://forums.wuggawoo.co.uk/A-Mimic-Class-coding-stuff-for-elite-only/t3948-1 I can't get the <br/>s to go and my numbering code above doesn't work because it does NON [code] post text.

    Any ideas? Help greatly appreciated!

  2. #2
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update, managed to get rid of the <br /> in a horrible way :s

    Code PHP:
    	private static function CodeTag($string) {
     
    		$str = str_replace("]\n", "]", $string);
    		$match = array('#\[code\](.*?)\[\/code\]#se');
    		$replace = array("'<div class=\"php_tag\">'.highlight_string(stripslashes('$1'), true).'</div>'");
    		$result = preg_replace($match, $replace, $str);
    		$result = str_replace('&lt;</span>', '', $result);
    		$result = str_replace('br&nbsp;', '', $result);
    		$result = str_replace('/&gt;', '', $result);		
    		return $result;
    		#$result	= explode("<br />", $result);
    		#$return = NULL;
    		#$x = 1;
    		#	foreach ($result as $line => $syntax) {
    		#		$return .= "<font color='black'>".$x."</font> ".$syntax."<br>";
    		#		$x++;
    		#	}
    
    		#return $return;
    	}

    Doesnt work if i do the entire string as

    Code HTML4Strict:
    <span style="color: rgb(0, 0, 187);">

    ^ seems to avoid detection.

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •