Page 13 of 13

Posted: Sun Jun 17, 2007 12:40 pm
by ziggy3000
here's my entire code

Code: Select all

function mysql($sql){
	// highlighting the code

	$sql = str_replace("\n", '<br />', $sql);

	//Quotes
	$sql = preg_replace("/(['\"`])(.+?)(['\"`])/", "<span class='quote'>\\1\\2\\3</span>", $sql);
	$sql = preg_replace('/`(.+?)`/i', "<span class='quote'>`\\1`</span>", $sql);

	//Equal Sign
 	$sql = preg_replace("/(=)(?!['\"][^>]*>)/", "<span class='operator'>\\1</span>", $sql);

	//Keywords 	
	$sql = preg_replace("/((CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+(\w)*[^<>])/i","<span class='keyword'>\\1</span>", $sql);
	$sql = preg_replace("/(SELECT|UPDATE|INSERT)/i", "<span class='keyword'>\\1</span>", $sql);
	$sql = preg_replace("/(MAX|AVG|SUM|COUNT|MIN|FROM|INTO)/i", "<span class='keyword'>\\1</span>", $sql);
	 //edited out very long keyword highlighting


	//Condition
	$sql = preg_replace('/(LIKE|NOT LIKE|REGEXP)/i', "<span class='condition'>\\1</span>", $sql);

	//Operator
	$sql = str_replace(";", "<span class='operator'>;</span>", $sql);
	$sql = preg_replace("/[0-9]{50}/", "<span class='number'>\\1</span>", $sql);		
	
	//Numbers
	$sql = preg_replace("/(\d{1,10})/", "<span class='number'>\\1</span>", $sql);		

	// Comments
	$sql = preg_replace("'(\/\*.*)(\w*)(.*\*/)'", "<span class='comment'>\\1\\2\\3</span>", $sql);
	$sql = preg_replace("'((//|#)((\w|\s|\d)*)*)'i", "<span class='comment'>\\1</span>", $sql);

//	$sql = preg_replace("/()/i", "<span class=''>\\1</span>", $sql);		
	
	// output the Code
	
	echo $this->output($sql, "grey");	
}

Posted: Sun Jun 17, 2007 12:43 pm
by ziggy3000
yea, that is not working for me. thats removing all text on that line except for // and # and even removes the break tag.

Posted: Sun Jun 17, 2007 12:47 pm
by ziggy3000
i found out why. it was a pretty stupid mistake. now it highlights everything but the numbers.
here's my html output

Code: Select all

<span class='comment'>// Test Comment number <span class='number'>1</span>
<br /></span><span class='comment'># This is the <span class='number'>2</span>nd comment
<br /></span>
i wonder why the css you gave me before isn't overwriting the color of the numbers?

Posted: Sun Jun 17, 2007 12:47 pm
by superdezign
You have to wrap up the entire expression as a subpattern, you know...

Edit: Show me the CSS you are using.

Posted: Sun Jun 17, 2007 12:48 pm
by ziggy3000
thats how i got it to work i mentioned that in the previous post

Posted: Sun Jun 17, 2007 12:50 pm
by ziggy3000

Code: Select all

<style>
	.operator{
		color: green;
	}
	.keyword{
		color: blue;
	}
	.comment{
		color: orange;
	}
	.comment *{
		color: orange;
	}
	.quote{
		color: red;
	}
	.number{
		color: darkblue;
	}
	.condition{
		color: orange;
	}
	code { padding-top: 2px; padding-right: 2px; padding-bottom: 2px; padding-left: 2px }
</style>

Posted: Sun Jun 17, 2007 12:52 pm
by ziggy3000
i have also encountered this problem for /* and */ type comments
it's just not overwriting the colors for the numbers. it overhighlights all other html tags

Posted: Sun Jun 17, 2007 12:59 pm
by superdezign
CSS is all about inheritance and overriding. You have the comment * too high up. Put it below the other styles, as they are overwriting it.

Posted: Sun Jun 17, 2007 2:41 pm
by ziggy3000
thanks ^_^

Posted: Sun Jun 17, 2007 4:22 pm
by superdezign
Look at that. Only took us a couple hundred posts. :P