Current location: Hot Scripts Forums » Programming Languages » PHP » bb code(php)


bb code(php)

Reply
  #1 (permalink)  
Old 11-07-04, 02:53 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
bb code(php)

i came up with this code:

<?php
function BBCode ($post)
{
$open_offset = strpos ($post, 'php');
$close_offset = strpos ($post, '/php');
$code_offset = $open_offset + 5;
$end_offset = $close_offset + 6;

$open_section = substr ($post, 0, $open_offset);
$code_section = substr ($post, $code_offset, $close_offset - $code_offset);
$close_section = substr ($post, $end_offset);

echo $open_section . '<br />';
highlight_string ($code_section);
echo '<br />' . $close_section;
}

$post=$row[2];

BBCode ($post);
?>

it does pretty much the same thing as these forums, notice i didnt use the [ ] around the word php, thats so that it wont show up as any code but i am aware of that.

this works fine ,but only will work for one peice of php code, (only one set of tags) and i know i have to use a loop but i am not good at loops, can someone tell me how plz? thx
one other thing, the page that it displays it on, the text is tiny, how come?
Reply With Quote
  #2 (permalink)  
Old 11-07-04, 03:01 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
http://phphat.net/tutorial.php?tid=1
thats what the font looks like small
Reply With Quote
  #3 (permalink)  
Old 11-07-04, 07:09 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
plz plz plz i need this fasst
Reply With Quote
  #4 (permalink)  
Old 11-07-04, 10:16 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
cmon Please i need tis fast
Reply With Quote
  #5 (permalink)  
Old 11-08-04, 06:40 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
this one is roughly done:
PHP Code:

function HighlightPHP($text) {

    $from = '~\[php\](.*?)\[\/php\]~eis';

    $to = "str_replace('\n', '', highlight_string(stripslashes(str_replace('\n', '',str_replace(array('&quot;','&gt;', '&lt;') , array('\"','>', '<'), '<?PHP\\1?>'))), TRUE));";

    $text = preg_replace($from, $to, $text);

    return $text;
}
you don't need to open php tags (<?PHP), all you need is to put your php code between [ php ]and[ /php ] (without space) and it will put its own tags and highlght .
it's also safe to use htmlspecialchars() with it ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #6 (permalink)  
Old 11-08-04, 01:16 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
i dont want to use that, how do i loop what i have got
?
Reply With Quote
  #7 (permalink)  
Old 11-08-04, 02:28 PM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by 4n7hr4x
i dont want to use that, how do i loop what i have got
?
just wonder if this is a good way to thank for other's help..

if you know how your script works i'm sure you'll later find that the behaviour you get is what it's expected to be. without using regex to match several patterns, the script will involve more magic. i prefer nevermind's way. it's simple, effective, and efficient. what you do is like reinventing the wheel for preg_replace function. if you want to do so, just go into your php-sourcedir/ext/pcre/php_pcre.c and see how it works.

regards,
__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #8 (permalink)  
Old 11-08-04, 02:35 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
i didnt mean to be rude, but i did not ask for another method, i asked how to loop, i will try his method for sure, but does no one know how to loop my method??
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Another POS BB code question Eclipse PHP 10 11-06-04 12:11 PM
bb codes? <?Wille?> PHP 14 11-04-04 09:50 AM


All times are GMT -5. The time now is 05:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.