PHP Code Box

Status
Not open for further replies.

chatmasta

Well-known member
Jan 7, 2007
2,611
68
48
NYC
Look how gross this is. You can barely even read it:

PHP:
<?php

function bbPage1($str)
{
    preg_match_all('/\[page\](.+?)\[\/page\]/ims', $str, $matches);
    $i = 0;
    foreach($matches as $key=>$val)
    {
        $str = preg_replace('/\[page\](.+?)\[\/page\]/ims', '[PAGE:' . $i . ']$1[/PAGE:' . $i . ']', $str, 1);
        $i++;
    }
    return $str;
}
/*
$str = '[PAGE]hey, baby.[/PAGE][PAGE]oh, hi.[/PAGE]';
echo $str . '<br /><br />';
$str = bbPage1($str);
echo $str;*/

function bbQuote($str){
    $str = preg_replace('/\[quote\](.+?)\[\/quote\]/ims', '<div class="quotebox">$1</div>', $str, 1);
    $str = preg_replace('/\[quote=(.+?)\](.+?)\[\/quote\]/ims', '<div class="quotebox"><div class="quotespeaker">Quote: Originally said by: $1</div>$2</div>', $str, 1);
    
    $prev = '';
    while ($prev != $str) {
        $prev = $str;
        $str = preg_replace('#\[quote\](.*?)\[/quote\]#si', '<blockquote><div><strong>Quote</strong><br />$1</div></blockquote>', $str);
        
    }
    
    return $str;
}
    
$str = '[quote]Hi.[quote]hi![/quote]hi[/quote]';
echo $str . '<br />';
$str = bbQuote($str);
echo $str;
?>

It wouldn't be too hard to change the background to white or something, would it? :bowdown:
 


whether or not you like sitepoint, they have an excellent VB plugin for pasting source code, regardless of the language
 
It's annoying when you're trying to help debug other people's code though, you don't really want to go through all the trouble in copy and pasting it into another app just to find out they left off a ; or they misspelled a function...
 
Status
Not open for further replies.