Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

84 users online



Implementing [PHP] Tags

Implementing [PHP] Tags

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 3
Adam

Adam

Status: Offline!

Implementing [PHP] Tags

I was able to do is using string posistions, suprisied myself there. But how can I do it with regular expression? I have regex that looks like:

PHP:


$Regex = '/(\[ PHP \])(.+)(\[\/ PHP \])/'; //spaces add to prevent vB parse
//replace with
$Output = preg_replace($Regex, hightlight_string("<?php".2."?>");


I think the string postions is impressive but I't can be used as easily as regex, and ideas or links?

PHP:


//string position code for the wonderors
$Text = "here is some code [ PHP ]print \$Var;[/ PHP ] look!";
$End = strpos($Text, "[/ PHP ]");
$Start = strpos($Text, "[ PHP ]");
$Length = ($End) - ($Start + 5);
$Code = substr($Text, $Start+5, $Length);
highlight_string("<?php ".$Code." ?>");

___________________


Current Project: LivermoreMuscle.com
Sig Hosted by Motorspin

m3th

m3th

Status: Offline!

That's an awsome idea..unfortuantly..im no help ::classic:

___________________

<?php
$var="Working on my sig :-P";
echo =$var;
?>

Adam

Adam

Status: Offline!

whats an awful idea? Coming from the guy who can't even do the php right in his sig.

___________________


Current Project: LivermoreMuscle.com
Sig Hosted by Motorspin

Jeb

Jeb

Status: Offline!

Perhaps you should read people's posts more carefully before you reply, Adman.

[i]That's an [b]awsome[/b] idea..unfortuantly..im no help[/i]

This forum sucks for displaying regexps. Bloody slash removal. Make sure you have slashes before your square brackets, etc etc....You're also missing the subject parameter of preg_replace.

[i]mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )[/i]

I have a feeling the [/ PHP] tag will cause an error in that slash - your delimiter is also a forward slash. I'm not sure if this causes an error or not, but I might suggest changing the delimiter to a hash or something.

___________________

Adam Goossens -- PHP is my mother tounge.

Linux: ( kernel.org | winehq ) -- f33l the p0w3r.

Nobody replying to your questions? Getting flamed? Getting told to RTFM? Ask your questions the right way.

ryno267

ryno267

GQ wannabe - lol
Status: Offline!

LOL at Adman - somebody stressed at work??

awesome, not awful.... Roll Eyes

___________________

Site: Rynoweb.com

CDude

CDude

nothing
Status: Offline!

save this for later

<pre>
<?


$str = 'Here is a php code {PHP] <? echo "help"; ?> [/PHP]. Cool eh?? Here are some more {PHP] <?
preg_match(\'/(\[PHP\])(.+?)(\[\/PHP\])/si\',$str,$match);
$c = $match[2];
highlight_string($c);

?>[/PHP] ';

preg_match_all('/(\{PHP\])(.+?)(\[\/PHP\])/si',$str,$match);
$codes = $match[2];
foreach($codes as $c){
$str = str_replace($c,highlight_string($c,TRUE),$str);
}
print $str;
?>
</pre>


change { to [ before testing

___________________

http://celerondude.com

CDude

CDude

nothing
Status: Offline!

now just figure out how to remove the tags in the hightlighted string

___________________

http://celerondude.com

CDude

CDude

nothing
Status: Offline!

done, here

<pre>
<?

$str = 'Here is a php code {PHP} <? echo "help"; ?> {/PHP]. Cool eh?? Here are some more {PHP} <?
preg_match(\'/(\[PHP\])(.+?)(\[\/PHP\])/si\',$str,$match);
$c = $match[2];
highlight_string($c);

?>{/PHP] ';

preg_match_all('/(\[PHP\])(.+?)(\[\/PHP\])/si',$str,$match);
$codes = $match[2];
foreach($codes as $i => $c){
$a = $match[1][$i];
$b = $match[3][$i];
$str = str_replace("$a$c$b",highlight_string($c,TRUE),$str);

}
print $str;
?>
</pre>

___________________

http://celerondude.com

CDude

CDude

nothing
Status: Offline!

test it first recessive

___________________

http://celerondude.com

Recessive

Recessive

Status: Offline!
Code:

function parsePHP( $string )
{
return preg_replace("/(?:\[php\])[\r\n]*(.*)(?:\[\/php\])/esi", "highlight_string('\\1', TRUE)", $string);
}

Highlighted in [code] tags due to [php] stripping tags.

Edit: See my below code for a better working version.

Last edited by Recessive, November 13th, 2002 09:52 AM (Edited 1 times)

Page 1 out of 3
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0199 seconds.