Jump to content

[SOLVED] Rendering form input


soycharliente

Recommended Posts

I created a basic forum. If someone tries to post something like the following:

 I ' m   r e a l l y   b o r e d .

It comes out like this:

I ' m r e a l l y b o r e d .

I know it's an HTML limitation.

 

Can anyone help me? What can I do so what it will render every character typed?

 

Here's my code:

<?php
while ($r = mysql_fetch_array($result)) {
$c++;
$id = $r["id"];
$threadid = $r["threadid"];
$author = getUsername($r["author"]);
$datetime = explode(" ", $r["created"]);
$ymd = explode("-", $datetime[0]);
$hms = explode(":", $datetime[1]);
$created = date("d F Y", mktime(0, 0, 0, $ymd[1], $ymd[2], $ymd[0]))." at ".date("H:i:s", mktime($hms[0] + getTimeOffset(), $hms[1], $hms[2], $ymd[1], $ymd[2], $ymd[0]));
$post = nl2br(htmlentities($r["post"], ENT_QUOTES)); // THIS LINE IS IT MAYBE???
$numposts = getNumUserPosts($r["author"]);
$ymd = explode("-", getJoinDate($r["author"]));
$join = date("d F Y", mktime(0, 0, 0, $ymd[1], $ymd[2], $ymd[0]));
echo ($c & 1) ? "<tr class=\"white\" valign=\"top\">\n" : "<tr class=\"bg_gray white\" valign=\"top\">\n";
echo "<td><strong>$author</strong><br />Posts: $numposts<br />Joined: $join</td>";
echo "<td>« Posted on $created EST »<p>- - - - - - - - - -<br />$post</p></td>";
echo "</tr>\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/
Share on other sites

Now anything that's longer than one line doesn't wrap to the next line because of the < pre > tags.

 

<?php
if (isset($_POST["submit_reply"])) {
$parentid = $_POST["parentid"];
$author = getUserId($_SESSION["user"]);
$reply = $_POST["reply"];
$error_reply = (empty($reply)) ? TRUE : FALSE;
$error_replylength = (strlen($reply) >= 5000) ? TRUE : FALSE;
if (!($error_reply||$error_replylength)) {
	dbconnect();
	$reply = myEscape($reply);
	$nreply = myWrap($reply, 70, "<br />\n");
	$result1 = mysql_query("INSERT INTO posts VALUES (NULL, '$parentid', '$author', NOW(), '$nreply')") or DIE("Error: Contact Webmaster. Code: submit-reply.");
	$result2 = mysql_query("UPDATE threads SET lastposter='$author', lastpostdate=NOW() WHERE id='$parentid'") or DIE("Error: Contact Webmaster. Code: updatethread-reply.");
	if ($result1&&$result2) {
		header("Location: showThread.php?id=$parentid");
		exit;
	}
}
}

function myWrap($str, $maxLength, $char){
    $wordEndChars = array(" ", "\n", "\r", "\f", "\v", "\0");
    $count = 0;
    $newStr = "";
    $openTag = FALSE;
    for ($i = 0; $i < strlen($str); $i++) {
        $newStr .= $str{$i};
        if ($str{$i} == "<") {
            $openTag = TRUE;
            continue;
        }
        if (($openTag) && ($str{$i} == ">")) {
            $openTag = FALSE;
            continue;
        }
        if (!$openTag){
            if(!in_array($str{$i}, $wordEndChars)) {
                $count++;
                if ($count == $maxLength) {
                    $newStr .= $char;
                    $count = 0;
                }
            } else {
                    $count = 0;
            }
        }
    }   
    return $newStr;
}
?>

 

That's how I'm using a wrapping function. Can we do something besides using < pre >?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.