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

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 2011-02-18 13:41

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

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