Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PHP BBCode Generator

Name: PHPAdvocate !MARtiNys66 2009-10-10 9:48

I wrote this for Tinychan, but it works on /prog/ too.  Enjoy!


<!doctype html>
<html>
    <head>
        <title>Tinychan BBCode Generator</title>
    </head>
   
    <body>
        <h1>Tinychan BBCode Generator</h1>
       
        <form action="" method="post">
            <div>
                <textarea name="plaintext" rows="10" cols="100"></textarea>
            </div>
           
            <div>
                <label for="mode" style="font-weight: bold;">Mode</label>
                <select id="mode" name="mode">
                    <option value="dominos">Dominos</option>
                    <option value="twister">Twister</option>
                </select>
            </div>
           
            <div>
                <input type="submit" name="do_bbcode" value="BECOME EXPERT PROGRAMMER" style="margin-top: 1em;" />
            </div>
        </form>

<?php

if($_POST['do_bbcode'])
{
    $string_chars = str_split($_POST['plaintext']);
    $bbcode = '';
   
    switch($_POST['mode'])
    {
        case 'dominos':
            foreach($string_chars as $char)
            {
                $bbcode .= '[spoiler]' . $char;
            }

            $bbcode .= str_repeat( '[/spoiler]', count($string_chars) );
           
            break;
           
        case 'twister':
            $arrays = array_chunk( $string_chars, ceil( count($string_chars) / 2 ) );
            $openings = $arrays[0];
            $closings = $arrays[1];
            $closing_position = count($closings) - 1;
           
            foreach($openings as $key => $char)
            {
               
                if(array_key_exists($key, $closings))
                {
                    $openings[$key] = '[spoiler]' . $char;
                    $closings[$closing_position] = $closings[$closing_position] . '[/spoiler]';
                }
                else
                {
                    $openings[$key] = '[spoiler]' . $char . '[/spoiler]';
                }
               
                $closing_position--;
            }
           
            $bbcode = implode( array_merge($openings, $closings) );
           
            break;
    }
   
    echo '<h2>Your BBCode</h2><textarea rows="5" cols="100">' . $bbcode . '</textarea>';
}

?>

    </body>
</html>


Dominos: PHP is superior.
Twister: PHP is superior.

Name: Anonymous 2009-10-10 10:00

well this is certainly a time saver.
kinda takes the EXPERT out of EXPERT BBCODE PROGRAMMER

Name: Anonymous 2009-10-10 10:00

gtfo, that code sucks

Name: Anonymous 2009-10-10 10:00

also, fuck your website

Name: Anonymous 2009-10-10 10:03

Name: Anonymous 2009-10-10 10:04

>>5
blank post indicates lack of understanding about what sage does.

Name: Anonymous 2009-10-10 10:11

Name: Anonymous 2009-10-10 10:21

Name: Anonymous 2009-10-10 10:23

(。◕‿‿◕。)imma bump this thread because i don't like newfags who don't understand sage.

Name: Anonymous 2009-10-10 10:32

>>9
You are the `newfag', sir.

Name: Anonymous 2009-10-10 10:34

>>9,10
You are both clueless.
And >>9 has two mouths.

Name: ANON IS LEGION 2009-10-10 10:36

>>9
BUMPING FOR EPIC WINFAG LEGENDARY THREAD FUCKING EPIC LULZ

Name: Anonymous 2009-10-10 10:38

>>10-12
what's wrong with disliking spammers?
that's what people who make blank sage posts are. just spammers like the HOT STRIPPING CODES guy.
sage does nothing except stop you from bumping the thread.

Name: Anonymous 2009-10-10 10:42

>>13
what's wrong with disliking spammers?
Nothing. I dislike them as well.
that's what people who make blank sage posts are. just spammers like the HOT STRIPPING CODES guy.
Close, except they are saging, so, unless the thread is on the top, it's not intrusive.
sage does nothing except stop you from bumping the thread.
Yes. Yes.

Name: PHPAdvocate !MARtiNys66 2009-10-10 13:34

>>3
What's wrong with my code?

>>4
Tinychan isn't my site.

Name: Anonymous 2009-10-10 14:47

Sorry fag, Perl is superior.

Name: Anonymous 2009-10-11 10:32

>>16
this.

Name: Anonymous 2010-11-02 9:26

Name: Anonymous 2011-02-03 6:10

Name: Anonymous 2011-02-04 19:47

Name: Anonymous 2011-02-18 13:41

<-- that's cool and all, but check 'em

Name: Anonymous 2013-02-10 19:37

>>22
Checked. Well done.

Don't change these.
Name: Email:
Entire Thread Thread List