Jump to content

RegExx or BBCodes??


gaza165

Recommended Posts

I am currently using BBCodes to do the code tag in my blog, I need a regular expression to search for php code and to change their colors acccordingly.

 

Just like PHP Freaks does....

 

variables are a color

functions are a colour.

 

Just like below, thats what i want to accomplish...

 

<?php

$string = str_replace($string,"Hello","Hello there..."
echo $string

?>

 

 

 

 

Link to comment
Share on other sites

Can somone please help me!!!!

 

I need a way to search for PHP code in my blog posts and to match the colors to fit with the code.

 

Just like phpfreaks does, hope someone can help me with this. Have been tearing my hair out over this.

 

Thanks

 

Garry

Link to comment
Share on other sites

I'd do something like this:

 

<?php

$code = <<<CODE
  some content
  goes here
<?php

morePHPcode();

while ( !($succeed = try()) );

echo 'foo'.\$bar;

?>
here's some <b>more</b> content, ect. ect.
CODE;

echo hiliteCode( $code );

function hiliteCode( $input ) {

$regex = '/<\?.*?\?>/s';
return preg_replace_callback(
	$regex,
	create_function(
		'$m',
		'return "<pre>".highlight_string( $m[0], TRUE )."</pre>";'
	),
	$input
);

}

?>

Link to comment
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.