Page 7 of 8

Posted: Tue Apr 17, 2007 7:23 pm
by RobertGonzalez
aaronhall wrote:I think this thread's about due for an updated summary, Kieran ;)
That's the only reason I am still posting in it.

Posted: Tue Apr 17, 2007 9:26 pm
by ziggy3000
i am using preg_replace_callback() but when i use the highlighting feature all it shows is

Code: Select all

1   Array
even though i am trying to parse '<?php phpinfo(); ?>' how would i fix this?

Posted: Wed Apr 18, 2007 5:34 pm
by ziggy3000
i dont know why it only highlights "Array"... it only says array in the bbcode function, and i am not even using that to highlight the code... any help?

Posted: Wed Apr 18, 2007 5:37 pm
by John Cartwright
It prints array because you are trying to use the array of matches (which is passed you to hc function) as a string.

Code: Select all

echo '<pre>';
print_r($code);
Put this inside your hc function. This will show you what your function is actually given.

Posted: Wed Apr 18, 2007 6:42 pm
by ziggy3000
now it prints
Array
(
[0] =>

Code: Select all

    [1] => 
)

PHP Code

1   Array
[/quote]

Posted: Wed Apr 18, 2007 9:32 pm
by Kieran Huggins
New summary:

:?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :!: :?: :banghead: :banghead: :banghead: :banghead: :banghead: :banghead:

Posted: Thu Apr 19, 2007 1:53 am
by aaronhall
I feel up to speed now. Thanks, Kieran

Posted: Fri Apr 20, 2007 6:20 pm
by ziggy3000
can someone help me on why it my code wont work??? :banghead: :banghead: :banghead: :banghead: :banghead: :banghead:

Posted: Sat Apr 21, 2007 2:00 pm
by neel_basu
Oh! My god I'vent seen Such a looooooooooooong post still now.

Posted: Sun Apr 22, 2007 3:22 pm
by ziggy3000
ok i found better code...
here is bbcode.php

Code: Select all

<?php
function bbcode($string){
$string = nl2br(htmlspecialchars($string));
$patterns = array(
                   '`\[b\](.+?)\[/b\]`is',
                   '`\[i\](.+?)\[/i\]`is',
                   '`\[u\](.+?)\[/u\]`is',
                   '`\[strike\](.+?)\[/strike\]`is',
                   '`\[color=#([0-9]{6})\](.+?)\[/color\]`is',
                   '`\[email\](.+?)\[/email\]`is',
                   '`\[img\](.+?)\[/img\]`is',
                   '`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
                   '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
                   '`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',
                   '`\[flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is',
                   '`\[quote\](.+?)\[/quote\]`is',
                   '`\[size=([1-6]+)\](.+?)\[/size\]`is'
                   );

$replaces =  array(
                      '<strong>\\1</strong>',
                      '<i>\\1</i>',
                      '<u>\\1</u>',
                      '<strike>\\1</strike>',
                      '<span style="color:#\1;">\2</span>',
                      '<a href="mailto:\1">\1</a>',
                      '<img src="\1" alt="" style="border:0px;" />',
                      '<a href="\1\2">\6</a>',
                      '<a href="\1\2">\1\2</a>',
                      '<a href="http://\1">\1</a>',
                      '<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>',
                      '<strong>Quote:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>\1</em></div>',
                      '<h\1>\2</h\1>'
                   );
$string = preg_replace($patterns, $replaces , $string);
return $string;
?>
and here is highlight.php

Code: Select all

<?php
function php($string){
$code_count = preg_match_all( '#\[php\](.*?)\[\/php\]#si', $string, $matches);

for( $i = 0; $i < $code_count; $i++ )
    {
        $replaced = $matches[1][$i];
     $replaced = hc( htmlspecialchars2( $replaced ));
         return $replaced;
    }
}

function htmlspecialchars2( $text )
{
    static $patterns, $replaces;
     if( !$patterns ){
        $patterns = array( '#<#', '#>#', '#&#', '#"#' );
        $replaces = array( '<', '>', '&', '"' );
    }
    return preg_replace( $patterns, $replaces, $text );
}

?>
i got these codes from here
http://www.isolated-designs.net/core/pr ... -functions

how would i combine those 2 together? i tried but it only does one or the other. can you just tell me the code from highlight.php that i should put in bbcode.php :)

Posted: Sun Apr 22, 2007 3:38 pm
by ziggy3000
i tried putting this code

Code: Select all

$code_count = preg_match_all( '#\[php\](.*?)\[\/php\]#si', $string, $matches);

     $string = hc( htmlspecialchars2($string));
         return $string;
    }
but the result is

Code: Select all

<i>test2</i>[php]<?php phpinfo(); ?>[/php] <strong>test</strong>
but it highlights the php code.

should i use preg_replace_callback() or what should i do?

(my original input was

Code: Select all

[i]test2[/i][php]<?php phpinfo(); ?>[/php] [b]test[/b]
)

Posted: Wed Apr 25, 2007 5:25 pm
by ziggy3000
does anyone know the solution to my problem???

this is me-> :banghead: :banghead: :banghead: :banghead: :banghead: :banghead:

Posted: Wed Apr 25, 2007 5:33 pm
by John Cartwright
your passing $string when you should be passing $matches[1] me thinks.

Posted: Wed Apr 25, 2007 5:38 pm
by ziggy3000
which part are you talking about...(i posted so much code, im confused :roll: )

Posted: Wed Apr 25, 2007 5:39 pm
by John Cartwright
I was referring to the last code you posted.