Antworten auf deine Fragen:
Neues Thema erstellen

Wo muss ich den Wordwrap einfügen damit es funktioniert

A

Ansem20

Guest

Hi erstmal ich habe ein kleines Problem und finde einfach die lösung nicht oder überseh es einfach. ich bin ein neuling in der Php Programmirung und habe mir ein kleines Script zusammengestellt nun habe ich ein kleines Problem mit der eintragslänge das ich diese mit wordwrap brechen kann weis ich nur weis ich nicht wo genau ich den Code einfügen muss damit er richtig funktioniert
hier einmal der Code für eure hilfe wäre ich sehr dankbar. Der erlichkeit halber nicht der ganze Code ist von mir geschrieben einge Elemente habe ich im Netz gefunden.
PHP:
  <?php
/*================================*\
       -- Variablen Start --
\*================================*/
define('ADMIN_USER',    '******');
define('ADMIN_PASS',    '******');

define('GB_FILE',    'guestbook.dat');
define('DATE_FORMAT',    'd - F - Y');
define('MAX_PER_PAGE',    10);

define('MAX_NAME_LEN',    32);
define('MIN_MESG_LEN',    3);
define('MAX_MESG_LEN',    600);
define('POST_TIME',    60);

define('ALLOW_URLS',    false);

define('SELF',        $_SERVER['PHP_SELF']);
/*================================*\
       -- Variablen Ende --
\*================================*/

define('FUNC', isset($_GET['func']) ? $_GET['func'] : NULL);
define('P', isset($_GET['p']) ? (int) $_GET['p'] : 1);

if (FUNC == 'logout') {
    echo '<p>ausgelogged</p>';

    setcookie ('password', '');
    unset($_COOKIE['password'], $password);
}

if (isset($_POST['password'])) {
    $password = md5($_POST['password']);

    if ($password == md5(ADMIN_PASS)) {
        setcookie('password', $password);
    }
} else {
    $password = isset($_COOKIE['password']) ? $_COOKIE['password'] : NULL;
}

ob_end_flush();


echo '<p><a href="'.SELF.'">Einträge</a> - <a href="'.SELF.'?func=sign">Neuen Eintrag schreiben</a>';
echo '</p>';
echo '<!-- guestbook from gbook.6te.net -->';

switch (FUNC)
{
/*================================*\
        -- Allgemein--
\*================================*/

default:
    if (!$fp = @fopen(GB_FILE, 'r')) {
        echo '<p>failed to open: '.GB_FILE.'</p>';
        break;
    }

    $i = 0;
    $data = NULL;

    $to_show = (P * MAX_PER_PAGE) - MAX_PER_PAGE;

    if (P > 1) echo '<p><b>Page '.P.'</b></p>';

    while (!feof($fp)) {
        $i++;

        if ($i > ($to_show + MAX_PER_PAGE)) break;

        $data = fgets($fp, 4096);

        if (empty($data)) break;

        if ($i > $to_show) {
            list ($date, $name, $mesg, $ip) = str_replace('\|', '|', preg_split('/(?<!\\\)(\|)/', $data));

            echo ("\n<p><b>Name:</b> $name  <br /><b>Datum:</b> ".date(DATE_FORMAT, $date)."<br /><b>Nachricht:</b><br />
$mesg</p><hr style=\"border-right: 0px solid #000; border-left: 0px solid #000; border-top: 0px solid #000; border-bottom: 3px outset #000000; height:0px;\" noshade=\"noshade\">");
            

        }
    }

    if ($i > MAX_PER_PAGE) {
        $line_count = substr_count(fread($fp, filesize(GB_FILE)), "\n") + $i;
        $line_count = ceil($line_count / MAX_PER_PAGE);

        $s = 1;
        $f = $line_count + 1;

        echo "\n".'<p>Page: # ';
        if ($line_count > MAX_PER_PAGE) {
            if (P < 6) {
                $s = 1;
                $f = 10;
            } elseif (($line_count-P) < 6) {
                $s = $line_count - 8;
                $f = $line_count;
            } else {
                $s = P -3;
                $f = $s + 8;
            }

            echo (P > 5) ? ' <a href="'.SELF.'">1</a>-' : NULL;
        }

        for ($k=$s; $k<$f; $k++) {
            echo ($k == P) ? "$k " : "<a href=\"".SELF."?p=$k\">$k</a> ";
        }

        echo ($k <= $line_count) ? "of <a href=\"".SELF."?p=$line_count\">$line_count</a></p>" : '</p>';

    }

    fclose($fp);
break;


/*================================*\
         -- Eingabe --
\*================================*/

case 'sign':
    $name = (isset($_POST['name'])) ? strip_chars($_POST['name']) : NULL;
    $mesg = (isset($_POST['mesg'])) ? strip_chars($_POST['mesg']) : NULL;

    if (isset($_POST['submit'])) {
        $errors = NULL;
        $now = time();

        $name_len = strlen($name);
        $mesg_len = strlen($mesg);
        
        if ($name) {
            if ($name_len > MAX_NAME_LEN) {
                $errors = '- Name is too long, '.$name_len.' (Max: '.MAX_NAME_LEN.')<br />';
            }
        } else {
            $errors = '- Name field is empty<br />';
        }
            
        if ($mesg) {
            if ($mesg_len > MAX_MESG_LEN) {
                $errors.= '- Message is too long, '.$mesg_len.' (Max: '.MAX_MESG_LEN.')<br />';
            } elseif ($mesg_len < MIN_MESG_LEN) {
                $errors.= '- Message is too short  (Min: '.MIN_MESG_LEN.')<br />';
            }
        } else {
            $errors.= '- Message field is empty<br />';
        }
            

        if (!$fp = @fopen(GB_FILE, 'r')) {
            echo 'Unable to open guestbook file for reading, check location and file permissions.';
            break;
        }

        list($date, , , $ip) = fgetcsv($fp, 4096, '|');

        fclose($fp);

        if ($_SERVER['REMOTE_ADDR'] == $ip && $now < $date+POST_TIME) {
            $errors.= '- You are posting too soon after your last post';
        }

        if ($errors) {
            echo '<p>'.$errors.'</p>';
        } else {
            if ($name == ADMIN_USER) {
                if (@$_POST['pass'] != ADMIN_PASS && $password != md5(ADMIN_PASS)) {
                    echo '<p>This username requires a password</p>';
                    echo '<form method="post" action="'.SELF.'?func=sign"><p><input type="password" name="pass" size="20" /> <input type="submit" value="Add" name="submit" /><input type="hidden" name="name" value="'.$name.'" /><input type="hidden" name="mesg" value="'.$mesg.'" /></p></form>';
                    break;
                }
            }

            $filesize = filesize(GB_FILE);
            $filesize = (empty($filesize)) ? 1024 : $filesize;

            if (!$fp = @fopen(GB_FILE, 'r+')) {
                echo 'Unable to open guestbook file for reading and writing, check location and file permissions.';
                break;
            }

            $data = fread($fp, $filesize);
            rewind($fp);

            fwrite($fp, "$now|".str_replace("\n", NULL, str_replace('|', '\|', $name)).' |'.str_replace("\n", '<br />', bbcode($mesg)).' |'.$_SERVER['REMOTE_ADDR'].'|');

            if (! empty($data)) fwrite($fp, "\n". $data);

            fclose($fp);

            echo '<p>wurde geändert<br />Go to the <a href="'.SELF.'">main</a> page to view it</p>';

            break;
        }

    }

    echo "\n".'<form method="post" action="'.SELF.'?func=sign"><p><label for="name">Name:</label><br /><input type="text" name="name" id="name" value="'.$name.'" size="24" /><br /><label for="mesg">Message:</label> <a href="'.SELF.'?func=bbcode">BBCode</a><br /><textarea name="mesg" id="mesg" cols="20" rows="4">'.$mesg.'</textarea><br /><input type="submit" name="submit" value="Add" /></p></form>';
break;


/*================================*\
         -- admin --
\*================================*/

case 'admin':
    if ($password == md5(ADMIN_PASS)) {
        if (isset($_GET['d'])) {
            /*================================*\
                 -- admin delete --
            \*================================*/

            if (isset($_GET['c'])) {
                if (!$fp = @fopen(GB_FILE, 'r')) {
                    echo 'Unable to open guestbook file for reading , check location and file permissions.';
                    break;
                }

                $output = '';

                while (!feof($fp)) {
                    $line = fgets($fp, 4096);

                    if (substr($line, 0, 10) == $_GET['d']) {
                        $output .= fread($fp, filesize(GB_FILE));

                        fclose($fp);

                        if (!$fp = @fopen(GB_FILE, 'w')) {
                            echo 'Unable to open guestbook file for writing, check location and file permissions.';
                            break;
                        }

                        fwrite($fp, $output);
                        fclose($fp);

                        echo '<p>Message has been <b>deleted</b>.<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page<br /></p>';
                        break 2;
                    } else {
                        $output .= $line;
                    }
                }

                fclose($fp);

                echo '<p>There was an error deleting this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
            }


            if (!$fp = @fopen(GB_FILE, 'r')) {
                echo 'Unable to open guestbook file for reading, check location and file permissions.';
                break;
            }

            while (!feof($fp)) {
                $line = fgets($fp, 4906);

                if (substr($line, 0, 10) == $_GET['d']) {
                    list($date, $name, $mesg) = explode ('|', $line);

                    echo '<p>Are you sure you want to delete this entry?</p>';
                    echo '<p><b>'.$name.'</b> - on '.date(DATE_FORMAT, $date).'<br />'.$mesg.'</p>';
                    echo '<p><a href="'.SELF.'?func=admin&amp;d='.$_GET['d'].'&amp;c=1">Yes</a> - <a href="'.SELF.'?func=admin">No</a></p>';

                    break 2;
                }
            }

            fclose($fp);

            echo '<p>There was an error finding this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
        } elseif (isset($_GET['e'])) {
            /*================================*\
                  -- admin edit --
            \*================================*/

            if (isset($_GET['c'])) {
                $name = (isset($_POST['name'])) ? strip_chars($_POST['name']) : NULL;
                $mesg = (isset($_POST['mesg'])) ? strip_chars($_POST['mesg']) : NULL;

                $errors = NULL;

                $name_len = strlen($name);
                $mesg_len = strlen($mesg);

                if ($name) {
                    if ($name_len > MAX_NAME_LEN) {
                        $errors = '- Name is too long, '.$name_len.' (Max: '.MAX_NAME_LEN.')<br />';
                    }
                } else {
                    $errors = '- Name field is empty<br />';
                }

                if ($mesg) {
                    if ($mesg_len > MAX_MESG_LEN) {
                        $errors.= '- Message is too long, '.$mesg_len.' (Max: '.MAX_MESG_LEN.')<br />';
                    } elseif ($mesg_len < MIN_MESG_LEN) {
                        $errors.= '- Message is too short  (Min: '.MIN_MESG_LEN.')<br />';
                    }
                } else {
                    $errors.= '- Message field is empty<br />';
                }

                if ($errors) {
                    echo '<p>'.$errors.'</p>';
                } else {
                    if (!$fp = @fopen(GB_FILE, 'r')) {
                        echo 'Unable to open guestbook file for reading, check location and file permissions.';
                        break;
                    }

                    $output = '';

                    while (!feof($fp)) {
                        $line = fgets($fp, 4096);

                        if (substr($line, 0, 10) == $_GET['e']) {
                            list($date, , , $ip) = str_replace('\|', '|', preg_split("/(?<!\\\)(\|)/", $line));

                            $output .= $date.'|'.str_replace("\n", NULL, str_replace('|', '\|', $name)).' |'.str_replace("\n", '<br />', bbcode($mesg)).' |'.$ip."|\n".fread($fp, filesize(GB_FILE));

                            fclose($fp);

                            $fp = @fopen(GB_FILE, 'w');
                                fwrite($fp, $output);
                            fclose($fp);

                            echo '<p>Message has been <b>edited</b>.<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page<br /></p>';

                            break 2;
                        } else {
                            $output .= $line;
                        }
                    }

                    fclose($fp);

                    echo '<p>There was an error finding this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
                }

            }

            if (isset($_POST['submit'])) {
                echo "\n".'<form method="post" action="'.SELF.'?func=admin&amp;e='.$_GET['e'].'&amp;c=1"><p><label for="name">Name:</label><br /><input type="text" name="name" id="name" value="'.$name.'" size="24" /><br /><label for="mesg">Message:</label> <a href="'.SELF.'?func=bbcode">BBCode</a><br /><textarea name="mesg" id="mesg" cols="20" rows="4">'.$mesg.'</textarea><br /><input type="submit" name="submit" value="Edit" /></p></form>';
                break;
            }


            if (!$fp = @fopen(GB_FILE, 'r')) {
                echo 'Unable to open guestbook file for reading, check location and file permissions.';
                break;
            }

            while (!feof($fp)) {
                $line = fgets($fp, 4906);

                if (substr($line, 0, 10) == $_GET['e']) {
                    list(, $name, $mesg) = str_replace('\|', '|', preg_split("/(?<!\\\)(\|)/", $line));

                    $mesg = preg_replace("(\<b\>(.+?)\<\/b>)is", "[b]$1[/b]", $mesg);
                    $mesg = preg_replace("(\<i\>(.+?)\<\/i\>)is", "[i]$1[/i]", $mesg);
                    $mesg = preg_replace("(\<u\>(.+?)\<\/u\>)is", "[u]$1[/u]", $mesg);
                    $mesg = preg_replace("(\<del\>(.+?)\<\/del\>)is", "[s]$1[/s]", $mesg);

                    $mesg = str_replace('<br />', "\n", $mesg);
                    $mesg = strip_tags($mesg);
                    
                    echo "\n".'<form method="post" action="'.SELF.'?func=admin&amp;e='.$_GET['e'].'&amp;c=1"><p><label for="name">Name:</label><br /><input type="text" name="name" id="name" value="'.$name.'" size="24" /><br /><label for="mesg">Message:</label> <a href="'.SELF.'?func=bbcode">BBCode</a><br /><textarea name="mesg" id="mesg" cols="20" rows="4">'.$mesg.'</textarea><br /><input type="submit" name="submit" value="Edit" /></p></form>';

                    break 2;
                }
            }

            fclose($fp);

            echo '<p>There was an error finding this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
        }
        else
        {
            /*================================*\
                 -- admin default --
            \*================================*/

            $gb_size = filesize(GB_FILE);

            echo '<p>======================<br />';
            echo 'File Size: '.round($gb_size / 1024, 1).'KB';
            echo '<br />======================</p>';

            if (!$fp = @fopen(GB_FILE, 'r')) {
                echo 'Unable to open guestbook file for reading and writing, check location and file permissions.';
                break;
            }

            $i = 0;
            $data = NULL;

            $to_show = (P * MAX_PER_PAGE) - MAX_PER_PAGE;

            if (P > 1) echo '<p><b>Page '.P.'</b></p>';

            while (!feof($fp)) {
                $i++;

                if ($i > ($to_show + MAX_PER_PAGE)) break;

                $data = fgets($fp, 4096);

                if (empty($data)) break;

                if ($i > $to_show) {
                    list ($date, $name, $mesg, $ip) = str_replace('\|', '|', preg_split("/(?<!\\\)(\|)/", $data));
                    echo ("\n<p><a href=\"".SELF."?func=admin&amp;e=$date\">[edit]</a> <a href=\"".SELF."?func=admin&amp;d=$date\">[delete]</a> <a href=\"http://whois.sc/$ip\">[whois]</a><br /><span><b>$name</b> on ".date(DATE_FORMAT, $date)."</span><br />$mesg</p>");
                }
            }

            if ($i > MAX_PER_PAGE) {
                $line_count = substr_count(fread($fp, $gb_size), "\n") + $i;
                $line_count = ceil($line_count / MAX_PER_PAGE);

                $s = 1;
                $f = $line_count + 1;

                echo "\n".'<p>Page: # ';

                if ($line_count > MAX_PER_PAGE) {
                    if (P < 6) {
                        $s = 1;
                        $f = 10;
                    } elseif (($line_count-P) < 6) {
                        $s = $line_count - 8;
                        $f = $line_count;
                    } else {
                        $s = P -3;
                        $f = $s + 8;
                    }

                    echo (P > 5) ? ' <a href="'.SELF.'?func=admin">1</a>-' : NULL;
                }

                for ($k=$s; $k<=$f; $k++) {
                    echo ($k == P) ? "$k " : "<a href=\"".SELF."?func=admin&amp;p=$k\">$k</a> ";
                }

                echo ($k <= $line_count) ? "of <a href=\"".SELF."?func=admin&amp;p=$line_count\">$line_count</a></p>" : '</p>';
            }

            fclose($fp);
        }
    } else {
        if (isset($_POST['submit'])) echo '<p>Sorry wrong password</p>';

        echo "\n".'<form method="post" action="'.SELF.'?func=admin"><p><input type="password" name="password" size="20" /> <input type="submit" value="Login" name="submit" /></p></form>';
    }
break;


/*================================*\
         -- BBCode --
\*================================*/
case 'bbcode':
    echo '
        <p>BBCode is a way of putting special effects into your text.  The allowed BBCode is:</p>
        <ul>
        <li>[b]<b>bold</b>[/b]</li>
        <li>[i]<i>italic</i>[/i]</li>
        <li>[u]<u>underline</u>[/u]</li>
        <li>[s]<del>strikethrough</del>[/s]</li>
        </ul>
        <p>For example: to make <b>this</b> bold.  when posting a message add the tags [b] and [/b] around the text (as seen above).</p>
    ';
break;
}


/*================================*\
       -- functions --
\*================================*/

function strip_chars($var) {
    return trim(str_replace("\r", NULL, htmlspecialchars(stripslashes(strip_tags($var)), ENT_QUOTES)));
}

function bbcode($var) {
    if (ALLOW_URLS == true)
        $var = preg_replace('/http:\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i', '<a href="$0">$0</a>', $var);

    $var = preg_replace('(\[b\](.+?)\[\/b\])is', '<b>$1</b>', $var);
    $var = preg_replace('(\[i\](.+?)\[\/i\])is', '<i>$1</i>', $var);
    $var = preg_replace('(\[u\](.+?)\[\/u\])is', '<u>$1</u>', $var);
    $var = preg_replace('(\[s\](.+?)\[\/s\])is', '<del>$1</del>', $var);

    return trim(str_replace('|', '\|', $var));
}

/*================================*\
     -- end functions --
\*================================*/


echo "\n";
echo '<p><a href="'.SELF.'?func=admin">Admin</a>'; if (!empty($password)) echo ' - <a href="'.SELF.'?func=logout">Logout</a>'; 
echo '</p>';
?>
<?php
/*
function myWordWrap ($mseg, $length=35, $wrap='\n', $from='left') {
    if ($from=='left') $txt=wordwrap($mseg, $length, $wrap, true);
    if ($from=='right') {
        // string to array
        $arr_l=array();
        for ($a=0;strlen($string)>$a;$a++) $arr_l[$a]=$string{$a};
        // reverse array
        $arr_r=array_reverse($arr_l);
        // array to string
        $string_r='';
        foreach ($arr_r as $arr_line => $arr) $string_r.=$arr;
        // add wrap to reverse string
        $string_r=wordwrap($string_r, $length, $wrap, true);
        // reverse string to array
        $arr_r=array();
        for ($a=0;strlen($string_r)>$a;$a++) $arr_r[]=$string_r{$a};
        // reverse array again
        $arr_l=array_reverse($arr_r);
        // string with wrap
        $txt='';
        foreach ($arr_l as $arr_line => $arr) $txt.=$arr;
        }
    return $txt;
    
    }
    **/
?>
 

Duddle

Posting-Frequenz: 14µHz

AW: Wo muss ich den Wordwrap einfügen damit es funktioniert

So weit ich das überblicken kann, gibst du nirgendwo Text aus. Falls ich das übersehen habe, bitte zeig es an.

Dort jedenfalls musst du den auszugebenden Text wordwrap() übergeben.


Duddle
 
A

Ansem20

Guest

AW: Wo muss ich den Wordwrap einfügen damit es funktioniert

Etwas unübersichtlich tut mir leid bin grad am aufräumen^^
PHP:
<?php
/*================================*\
       -- Variablen Start --
\*================================*/
define('ADMIN_USER',        'admin');
define('ADMIN_PASS',   'MreSephi10');

define('GB_FILE',    'guestbook.dat');
define('DATE_FORMAT',    'd - F - Y');
define('MAX_PER_PAGE',              10);

define('MAX_NAME_LEN',             32);
define('MIN_MESG_LEN',              3);
define('MAX_MESG_LEN',            600);
define('POST_TIME',                 60);

define('ALLOW_URLS',    false);

define('SELF',        $_SERVER['PHP_SELF']);
/*================================*\
       -- Variablen Ende --
\*================================*/

define('FUNC', isset($_GET['func']) ? $_GET['func'] : NULL);
define('P', isset($_GET['p']) ? (int) $_GET['p'] : 1);

if (FUNC == 'logout') {
    echo '<p>ausgelogged</p>';

    setcookie ('password', '');
    unset($_COOKIE['password'], $password);
}

if (isset($_POST['password'])) {
    $password = md5($_POST['password']);

    if ($password == md5(ADMIN_PASS)) {
        setcookie('password', $password);
    }
} else {
    $password = isset($_COOKIE['password']) ? $_COOKIE['password'] : NULL;
}

ob_end_flush();


echo '<p><a href="'.SELF.'">Einträge</a>    -    <a href="'.SELF.'?func=sign">Neuen Eintrag schreiben</a>';
echo '</p>';
echo '</p>';
echo '</p>';
echo '<!-- guestbook from gbook.6te.net -->';

switch (FUNC)
{
/*================================*\
        -- Allgemein--
\*================================*/

default:
    if (!$fp = @fopen(GB_FILE, 'r')) {
        echo '<p>failed to open: '.GB_FILE.'</p>';
        break;
    }

    $i = 0;
    $data = NULL;

    $to_show = (P * MAX_PER_PAGE) - MAX_PER_PAGE;

    if (P > 1) echo '<p><b>Page '.P.'</b></p>';

    while (!feof($fp)) {
        $i++;

        if ($i > ($to_show + MAX_PER_PAGE)) break;

        $data = fgets($fp, 4096);

        if (empty($data)) break;

        if ($i > $to_show) {
            list ($date, $name, $mesg, $ip) = str_replace('\|', '|', 
            preg_split('/(?<!\\\)(\|)/', $data));
            
    /* ==========Text ausgabe beginnt hier==========*/
        
            echo ("\n<p><b>Name:</b> $name  <br />
                  <b>Datum:</b> ".date(DATE_FORMAT, $date)."<br />
                  <b>Nachricht:</b> <br/>$mesg </p> 
                  <hr style=\"border-right: 0px solid #000; 
                  border-left: 0px solid     #000; 
                  border-top: 0px solid #000; 
                  border-bottom: 3px outset #000000; height:0px;\"
                  color: #B60000;\"
                  noshade=\"noshade\">");
            

        }
    }

    if ($i > MAX_PER_PAGE) {
        $line_count = substr_count(fread($fp, filesize(GB_FILE)), "\n") + $i;
        $line_count = ceil($line_count / MAX_PER_PAGE);

        $s = 1;
        $f = $line_count + 1;

        echo "\n".'<p>Page: # ';
        if ($line_count > MAX_PER_PAGE) {
            if (P < 6) {
                $s = 1;
                $f = 10;
            } elseif (($line_count-P) < 6) {
                $s = $line_count - 8;
                $f = $line_count;
            } else {
                $s = P -3;
                $f = $s + 8;
            }

            echo (P > 5) ? ' <a href="'.SELF.'">1</a>-' : NULL;
        }

        for ($k=$s; $k<$f; $k++) {
            echo ($k == P) ? "$k " : "<a href=\"".SELF."?p=$k\">$k</a> ";
        }

        echo ($k <= $line_count) ? "of <a href=\"".SELF."?p=$line_count\">$line_count</a></p>" : '</p>';

    }

    fclose($fp);
break;


/*================================*\
         -- Eingabe --
\*================================*/

case 'sign':
    $name = (isset($_POST['name'])) ? strip_chars($_POST['name']) : NULL;
    $mesg = (isset($_POST['mesg'])) ? strip_chars($_POST['mesg']) : NULL;

    if (isset($_POST['submit'])) {
        $errors = NULL;
        $now = time();

        $name_len = strlen($name);
        $mesg_len = strlen($mesg);
        
        if ($name) {
            if ($name_len > MAX_NAME_LEN) {
                $errors = '- Name is too long, '.$name_len.' (Max: '.MAX_NAME_LEN.')<br />';
            }
        } else {
            $errors = '- Name field is empty<br />';
        }
            
        if ($mesg) {
            if ($mesg_len > MAX_MESG_LEN) {
                $errors.= '- Message is too long, '.$mesg_len.' (Max: '.MAX_MESG_LEN.')<br />';
            } elseif ($mesg_len < MIN_MESG_LEN) {
                $errors.= '- Message is too short  (Min: '.MIN_MESG_LEN.')<br />';
            }
        } else {
            $errors.= '- Message field is empty<br />';
        }
            

        if (!$fp = @fopen(GB_FILE, 'r')) {
            echo 'Unable to open guestbook file for reading, check location and file permissions.';
            break;
        }

        list($date, , , $ip) = fgetcsv($fp, 4096, '|');

        fclose($fp);

        if ($_SERVER['REMOTE_ADDR'] == $ip && $now < $date+POST_TIME) {
            $errors.= '- You are posting too soon after your last post';
        }

        if ($errors) {
            echo '<p>'.$errors.'</p>';
        } else {
            if ($name == ADMIN_USER) {
                if (@$_POST['pass'] != ADMIN_PASS && $password != md5(ADMIN_PASS)) {
                    echo '<p>This username requires a password</p>';
                    echo '<form method="post" action="'.SELF.'?func=sign"><p>
                    <input type="password" name="pass" size="20" /> 
                    <input type="submit" value="Add" name="submit" />
                    <input type="hidden" name="name" value="'.$name.'" />
                    <input type="hidden" name="mesg" value="'.$mesg.'" /></p>
                    </form>';
                    break;
                }
            }

            $filesize = filesize(GB_FILE);
            $filesize = (empty($filesize)) ? 1024 : $filesize;

            if (!$fp = @fopen(GB_FILE, 'r+')) {
                echo 'Unable to open guestbook file for reading and writing, check location and file permissions.';
                break;
            }

            $data = fread($fp, $filesize);
            rewind($fp);

            fwrite($fp, "$now|".str_replace("\n", NULL, str_replace('|', '\|', $name)).' |'.str_replace("\n", '<br />', bbcode($mesg)).' |'.$_SERVER['REMOTE_ADDR'].'|');

            if (! empty($data)) fwrite($fp, "\n". $data);

            fclose($fp);

            echo '<p>wurde geändert<br />Go to the <a href="'.SELF.'">main</a> page to view it</p>';

            break;
        }

    }

    echo "\n".'<form method="post" action="'.SELF.'?func=sign"><p>
    <label for="name">Name:</label><br /><input type="text" name="name" id="name"
    value="'.$name.'" size="24" /><br />
    <label for="mesg">Message:</label> <a href="'.SELF.'?func=bbcode">BBCode</a><br />
    <textarea name="mesg" id="mesg" cols="50" rows="4">'.$mesg.'</textarea><br />
    <input type="submit" name="submit" value="Add" /></p></form>';
break;


/*================================*\
         -- admin --
\*================================*/

case 'admin':
    if ($password == md5(ADMIN_PASS)) {
        if (isset($_GET['d'])) {
            /*================================*\
                 -- admin delete --
            \*================================*/

            if (isset($_GET['c'])) {
                if (!$fp = @fopen(GB_FILE, 'r')) {
                    echo 'Unable to open guestbook file for reading , check location and file permissions.';
                    break;
                }

                $output = '';

                while (!feof($fp)) {
                    $line = fgets($fp, 4096);

                    if (substr($line, 0, 10) == $_GET['d']) {
                        $output .= fread($fp, filesize(GB_FILE));

                        fclose($fp);

                        if (!$fp = @fopen(GB_FILE, 'w')) {
                            echo 'Unable to open guestbook file for writing, check location and file permissions.';
                            break;
                        }

                        fwrite($fp, $output);
                        fclose($fp);

                        echo '<p>Message has been <b>deleted</b>.<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page<br /></p>';
                        break 2;
                    } else {
                        $output .= $line;
                    }
                }

                fclose($fp);

                echo '<p>There was an error deleting this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
            }


            if (!$fp = @fopen(GB_FILE, 'r')) {
                echo 'Unable to open guestbook file for reading, check location and file permissions.';
                break;
            }

            while (!feof($fp)) {
                $line = fgets($fp, 4906);

                if (substr($line, 0, 10) == $_GET['d']) {
                    list($date, $name, $mesg) = explode ('|', $line);

                    echo '<p>Soll der eintrag wirklich gelöscht werden</p>';
                    echo '<p><b>'.$name.'</b> - on '.date(DATE_FORMAT, $date).'<br />'.$mesg.'</p>';
                    echo '<p><a href="'.SELF.'?func=admin&amp;d='.$_GET['d'].'&amp;c=1">Yes</a> - <a href="'.SELF.'?func=admin">No</a></p>';

                    break 2;
                }
            }

            fclose($fp);

            echo '<p>There was an error finding this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
        } elseif (isset($_GET['e'])) {
            /*================================*\
                  -- admin edit --
            \*================================*/

            if (isset($_GET['c'])) {
                $name = (isset($_POST['name'])) ? strip_chars($_POST['name']) : NULL;
                $mesg = (isset($_POST['mesg'])) ? strip_chars($_POST['mesg']) : NULL;

                $errors = NULL;

                $name_len = strlen($name);
                $mesg_len = strlen($mesg);

                if ($name) {
                    if ($name_len > MAX_NAME_LEN) {
                        $errors = '- Name is too long, '.$name_len.' (Max: '.MAX_NAME_LEN.')<br />';
                    }
                } else {
                    $errors = '- Name field is empty<br />';
                }

                if ($mesg) {
                    if ($mesg_len > MAX_MESG_LEN) {
                        $errors.= '- Message is too long, '.$mesg_len.' (Max: '.MAX_MESG_LEN.')<br />';
                    } elseif ($mesg_len < MIN_MESG_LEN) {
                        $errors.= '- Message is too short  (Min: '.MIN_MESG_LEN.')<br />';
                    }
                } else {
                    $errors.= '- Message field is empty<br />';
                }

                if ($errors) {
                    echo '<p>'.$errors.'</p>';
                } else {
                    if (!$fp = @fopen(GB_FILE, 'r')) {
                        echo 'Unable to open guestbook file for reading, check location and file permissions.';
                        break;
                    }

                    $output = '';

                    while (!feof($fp)) {
                        $line = fgets($fp, 4096);

                        if (substr($line, 0, 10) == $_GET['e']) {
                            list($date, , , $ip) = str_replace('\|', '|', preg_split("/(?<!\\\)(\|)/", $line));

                            $output .= $date.'|'.str_replace("\n", NULL, str_replace('|', '\|', $name)).' |'.str_replace("\n", '<br />', bbcode($mesg)).' |'.$ip."|\n".fread($fp, filesize(GB_FILE));

                            fclose($fp);

                            $fp = @fopen(GB_FILE, 'w');
                                fwrite($fp, $output);
                            fclose($fp);

                            echo '<p>Message has been <b>edited</b>.<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page<br /></p>';

                            break 2;
                        } else {
                            $output .= $line;
                        }
                    }

                    fclose($fp);

                    echo '<p>There was an error finding this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
                }

            }

            if (isset($_POST['submit'])) {
                echo "\n".'<form method="post" action="'.SELF.'?func=admin&amp;
                e='.$_GET['e'].'&amp;c=1"><p>
                <label for="name">Name:</label><br /><input type="text" name="name"
                 id="name" value="'.$name.'" size="24" /><br />
                <label for="mesg">Nachricht:</label> <a href="'.SELF.'?func=bbcode">
                BBCode</a><br />
                <textarea name="mesg" id="mesg" cols="50" rows="4">'.$mesg.'
                </textarea><br />
                <input type="submit" name="submit" value="Edit" /></p></form>';
                break;
            }


            if (!$fp = @fopen(GB_FILE, 'r')) {
                echo 'Unable to open guestbook file for reading, check location and file permissions.';
                break;
            }

            while (!feof($fp)) {
                $line = fgets($fp, 4906);

                if (substr($line, 0, 10) == $_GET['e']) {
                    list(, $name, $mesg) = str_replace('\|', '|', preg_split("/(?<!\\\)(\|)/", $line));

                    $mesg = preg_replace("(\<b\>(.+?)\<\/b>)is", "[b]$1[/b]", $mesg);
                    $mesg = preg_replace("(\<i\>(.+?)\<\/i\>)is", "[i]$1[/i]", $mesg);
                    $mesg = preg_replace("(\<u\>(.+?)\<\/u\>)is", "[u]$1[/u]", $mesg);
                    $mesg = preg_replace("(\<del\>(.+?)\<\/del\>)is", "[s]$1[/s]", $mesg);

                    $mesg = str_replace('<br />', "\n", $mesg);
                    $mesg = strip_tags($mesg);
                    
                    echo "\n".'<form method="post" action="'.SELF.'?func=admin&amp;
                    e='.$_GET['e'].'&amp;c=1"><p>
                    <label for="name">Name:</label><br /><input type="text"
                     name="name" id="name" value="'.$name.'" size="24" /><br />
                    <label for="mesg">Nachricht:</label> 
                    <a href="'.SELF.'?func=bbcode">BBCode</a><br />
                    <textarea name="mesg" id="mesg" cols="50" rows="4">'.$mesg.'
                    </textarea><br /><input type="submit" name="submit" value="Edit"
                     /></p></form>';

                    break 2;
                }
            }

            fclose($fp);

            echo '<p>There was an error finding this post, it doesn\'t seem to exist<br />Go back to the <a href="'.SELF.'?func=admin">admin</a> page and try again</p>';
        }
        else
        {
            /*================================*\
                 -- admin default --
            \*================================*/

            $gb_size = filesize(GB_FILE);

            echo '<p>======================<br />';
            echo 'File Size: '.round($gb_size / 1024, 1).'KB';
            echo '<br />======================</p>';

            if (!$fp = @fopen(GB_FILE, 'r')) {
                echo 'Unable to open guestbook file for reading and writing, check location and file permissions.';
                break;
            }

            $i = 0;
            $data = NULL;

            $to_show = (P * MAX_PER_PAGE) - MAX_PER_PAGE;

            if (P > 1) echo '<p><b>Page '.P.'</b></p>';

            while (!feof($fp)) {
                $i++;

                if ($i > ($to_show + MAX_PER_PAGE)) break;

                $data = fgets($fp, 4096);

                if (empty($data)) break;

                if ($i > $to_show) {
                    list ($date, $name, $mesg, $ip) = str_replace('\|', '|', preg_split("/(?<!\\\)(\|)/", $data));
                    echo ("\n<p><a href=\"".SELF."?func=admin&amp;e=$date\">
                    [edit]</a> <a href=\"".SELF."?func=admin&amp;d=$date\">[delete]
                    </a> <a href=\"http://whois.sc/$ip\">[whois]</a>
                    <br /><span><b>$name</b> on ".date(DATE_FORMAT, $date)."</span>
                    <br />$mesg</p>");
                }
            }

            if ($i > MAX_PER_PAGE) {
                $line_count = substr_count(fread($fp, $gb_size), "\n") + $i;
                $line_count = ceil($line_count / MAX_PER_PAGE);

                $s = 1;
                $f = $line_count + 1;

                echo "\n".'<p>Page: # ';

                if ($line_count > MAX_PER_PAGE) {
                    if (P < 6) {
                        $s = 1;
                        $f = 10;
                    } elseif (($line_count-P) < 6) {
                        $s = $line_count - 8;
                        $f = $line_count;
                    } else {
                        $s = P -3;
                        $f = $s + 8;
                    }

                    echo (P > 5) ? ' <a href="'.SELF.'?func=admin">1</a>-' : NULL;
                }

                for ($k=$s; $k<=$f; $k++) {
                    echo ($k == P) ? "$k " : "<a href=\"".SELF."?func=admin&amp;p=$k\">$k</a> ";
                }

                echo ($k <= $line_count) ? "of <a href=\"".SELF."?func=admin&amp;p=$line_count\">$line_count</a></p>" : '</p>';
            }

            fclose($fp);
        }
    } else {
        if (isset($_POST['submit'])) echo '<p>Sorry wrong password</p>';

        echo "\n".'<form method="post" action="'.SELF.'?func=admin"><p>
        <input type="password" name="password" size="20" /> 
        <input type="submit" value="Login" name="submit" /></p></form>';
    }
break;


/*================================*\
         -- BBCode --
\*================================*/
case 'bbcode':
    echo '
        <p>BBCode is a way of putting special effects into your text.  The allowed BBCode is:</p>
        <ul>
        <li>[b]<b>bold</b>[/b]</li>
        <li>[i]<i>italic</i>[/i]</li>
        <li>[u]<u>underline</u>[/u]</li>
        <li>[s]<del>strikethrough</del>[/s]</li>
        </ul>
        <p>For example: to make <b>this</b> bold.  when posting a message add the tags [b] and [/b] around the text (as seen above).</p>
    ';
break;
}


/*================================*\
       -- functions --
\*================================*/

function strip_chars($var) {
    return trim(str_replace("\r", NULL, htmlspecialchars(stripslashes(strip_tags($var)), ENT_QUOTES)));
}

function bbcode($var) {
    if (ALLOW_URLS == true)
        $var = preg_replace('/http:\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i', '<a href="$0">$0</a>', $var);

    $var = preg_replace('(\[b\](.+?)\[\/b\])is', '<b>$1</b>', $var);
    $var = preg_replace('(\[i\](.+?)\[\/i\])is', '<i>$1</i>', $var);
    $var = preg_replace('(\[u\](.+?)\[\/u\])is', '<u>$1</u>', $var);
    $var = preg_replace('(\[s\](.+?)\[\/s\])is', '<del>$1</del>', $var);

    return trim(str_replace('|', '\|', $var));
}

/*================================*\
     -- end functions --
\*================================*/


echo "\n";
echo '<p><a href="'.SELF.'?func=admin">Admin</a>'; if (!empty($password)) echo ' - <a href="'.SELF.'?func=logout">Logout</a>'; 
echo '</p>';
?>
<?php
/*
function myWordWrap ($mseg, $length=35, $wrap='\n', $from='left') {
    if ($from=='left') $txt=wordwrap($mseg, $length, $wrap, true);
    if ($from=='right') {
        // string to array
        $arr_l=array();
        for ($a=0;strlen($string)>$a;$a++) $arr_l[$a]=$string{$a};
        // reverse array
        $arr_r=array_reverse($arr_l);
        // array to string
        $string_r='';
        foreach ($arr_r as $arr_line => $arr) $string_r.=$arr;
        // add wrap to reverse string
        $string_r=wordwrap($string_r, $length, $wrap, true);
        // reverse string to array
        $arr_r=array();
        for ($a=0;strlen($string_r)>$a;$a++) $arr_r[]=$string_r{$a};
        // reverse array again
        $arr_l=array_reverse($arr_r);
        // string with wrap
        $txt='';
        foreach ($arr_l as $arr_line => $arr) $txt.=$arr;
        }
    return $txt;
    
    }
    **/
?>
 
A

Ansem20

Guest

AW: Wo muss ich den Wordwrap einfügen damit es funktioniert

Die Länge wird überprüft weis ich ja auch ist ja auf 600 begrenzt nur habe ich das Problem das es keinen Automatischen Zeilenumbruch gibt nach ca50 zeichen. heist wenn ein spassvogel alles in eine Zeile schreibt zieht sich das layout etwas auseinander
 

netbandit

Aktives Mitglied

AW: Wo muss ich den Wordwrap einfügen damit es funktioniert

Also so wie ich das sehe müsste in Zeile 328 eine Änderung erfolgen; um $mesg müsstest Du irgendwie

PHP:
wordwrap($mesg, 50, "\n", true);
einbauen. Der Übersicht halber würde ich die Formatierungen in eine Funktion unterbringen und dort anwenden.

Aber: Da Umbrüche in den Beiträgen erlaubt sind, wirst Du mit wordwrap u.U. nicht wirklich schöne Ergebnisse erzielen. Da macht es dann vielleicht doch Sinn nach Wörtern mit mehr als x Zeichen zu suchen und einen Trenner (Bindestrich) einzufügen.

Einen Lösungsansatz bietet z.B. der erste Kommentar auf php.net - wordwrap, da müsste allerdings noch ein wenig angepasst werden (wordwrap raus usw.)

Grüße :)
 
Bilder bitte hier hochladen und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Antworten auf deine Fragen:
Neues Thema erstellen

Willkommen auf PSD-Tutorials.de

In unseren Foren vernetzt du dich mit anderen Personen, um dich rund um die Themen Fotografie, Grafik, Gestaltung, Bildbearbeitung und 3D auszutauschen. Außerdem schalten wir für dich regelmäßig kostenlose Inhalte frei. Liebe Grüße senden dir die PSD-Gründer Stefan und Matthias Petri aus Waren an der Müritz. Hier erfährst du mehr über uns.

Stefan und Matthias Petri von PSD-Tutorials.de

Nächster neuer Gratisinhalt

03
Stunden
:
:
25
Minuten
:
:
19
Sekunden

Flatrate für Tutorials, Assets, Vorlagen

Zurzeit aktive Besucher

Keine Mitglieder online.

Statistik des Forums

Themen
118.565
Beiträge
1.538.067
Mitglieder
67.488
Neuestes Mitglied
Andrew56524
Oben