soycharliente Posted July 12, 2007 Share Posted July 12, 2007 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/ Share on other sites More sharing options...
trq Posted July 12, 2007 Share Posted July 12, 2007 You could simply place the data between <pre></pre> tags. Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/#findComment-296382 Share on other sites More sharing options...
per1os Posted July 12, 2007 Share Posted July 12, 2007 surround it in < pre> and </ pre> tags. Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/#findComment-296383 Share on other sites More sharing options...
soycharliente Posted July 12, 2007 Author Share Posted July 12, 2007 That causes it to be indented because of how the code is indented in the file. Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/#findComment-296384 Share on other sites More sharing options...
soycharliente Posted July 12, 2007 Author Share Posted July 12, 2007 Wait. It's not doing it anymore. What the crap? It's not indenting anymore. That works. Weird. Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/#findComment-296389 Share on other sites More sharing options...
soycharliente Posted July 12, 2007 Author Share Posted July 12, 2007 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 >? Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/#findComment-296400 Share on other sites More sharing options...
soycharliente Posted July 13, 2007 Author Share Posted July 13, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/#findComment-297369 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 *bump* $data = str_replace(" ", " ", $data); then print the data. Quote Link to comment https://forums.phpfreaks.com/topic/59642-solved-rendering-form-input/#findComment-297374 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.