Noskiw Posted October 30, 2009 Share Posted October 30, 2009 <?php $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); if(!$_POST['submit']){ echo " <form action='index.php?p=blog&p=admin' method='POST'> <table width='100%'> <tr> <td> Title: </td> <td> <input type='text' name='title' maxlength='32' /> </td> </tr> <tr> <td width='9%' valign='top'> Your Name: </td> <td valign='top'> <input type='text' name='name' maxlength='32' /> </td> </tr> <tr> <td valign='top'> Your Email: </td> <td> <input type='text' name='email' maxlength='35' /> </td> </tr> <tr> <td valign='top'> Your Post: </td> <td> <textarea cols='50' rows='5' name='message' maxlength='250'></textarea> <p><input type='submit' name='submit' value='Post' /> </td> </tr> </table> </form>"; }else{ $title = $_POST['title']; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $date = date("Y-m-d"); $time = date("H:i:s"); if($name && $email && $message){ $querypost = mysql_query("INSERT INTO blog VALUES('','" . $title . "','" . $name . "','" . $email . "','" . $message . "','" . $time . "','" . $date . "')"); echo "<hr />Please wait... <meta http-equiv='refresh' content='2'>\n"; echo "Successfuly posted!"; } } ?> <?php $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); echo "<h1>Blog</h1>"; $query = mysql_query("SELECT * FROM blog"); if (mysql_num_rows($query) == 0) { echo "<hr />There are no posts yet, make the first in the admin section!"; } else { while ($row = mysql_fetch_assoc($query)) { echo "<hr />"; $title2 = $row['title']; $name = $row['name']; $email = $row['email']; $post = $row['post']; $date = $row['date']; $time = $row['time']; echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(strip_tags($post)) . "</td></tr></table>\n"; } } echo "<hr />"; echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>"; ?> I figured that it would be one of these two pages of code. I want to have a line break after 100 characters. I've tried... <?php $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); if(!$_POST['submit']){ echo " <form action='index.php?p=blog&p=admin' method='POST'> <table width='100%'> <tr> <td> Title: </td> <td> <input type='text' name='title' maxlength='32' /> </td> </tr> <tr> <td width='9%' valign='top'> Your Name: </td> <td valign='top'> <input type='text' name='name' maxlength='32' /> </td> </tr> <tr> <td valign='top'> Your Email: </td> <td> <input type='text' name='email' maxlength='35' /> </td> </tr> <tr> <td valign='top'> Your Post: </td> <td> <textarea cols='50' rows='5' name='message' maxlength='250'></textarea> <p><input type='submit' name='submit' value='Post' /> </td> </tr> </table> </form>"; }else{ $title = $_POST['title']; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $date = date("Y-m-d"); $time = date("H:i:s"); if($name && $email && $message){ $querypost = mysql_query("INSERT INTO blog VALUES('','" . $title . "','" . $name . "','" . $email . "','" . $message . "','" . $time . "','" . $date . "')"); if(strlen($message) < 50){ $querypost.= mysql_query("INSERT INTO blog VALUES('','" . $title . "','" . $name . "','" . $email . "','" . $message + "<br />" . "','" . $time . "','" . $date . "')"); } echo "<hr />Please wait... <meta http-equiv='refresh' content='2'>\n"; echo "Successfuly posted!"; } } ?> But this didn't seem to work. Could someone please help me. Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/ Share on other sites More sharing options...
Mchl Posted October 30, 2009 Share Posted October 30, 2009 Apply wordwrap to the string you want... wrapped. Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948097 Share on other sites More sharing options...
Noskiw Posted October 30, 2009 Author Share Posted October 30, 2009 I applied wordwrap like you said, but to put it in short terms, there was no effect what so ever. <?php $connect = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("blog", $connect) or die(mysql_error()); function bbcode($string) { if ($string) { $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]', ' ', '', ''); $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>', '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">', '</div></center>', '<img src="', '">', '<img src="http://localhost/images/P.png" width="30" height="30" />'); $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string); return $new_string_2; } } echo "<h1>Blog</h1>"; $query = mysql_query("SELECT * FROM blog"); if (mysql_num_rows($query) == 0) { echo "<hr />There are no posts yet, make the first in the admin section!"; } else { while ($row = mysql_fetch_assoc($query)) { echo "<hr />"; $title2 = $row['title']; $name = $row['name']; $email = $row['email']; $post = $row['post']; $date = $row['date']; $time = $row['time']; $text = $post; $new = wordwrap($text, 50, "<br />", true); echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " . $name . "(" . $email . ") at " . $time . " on " . $date . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags($new . "<br />"))) . "</td></tr></table>\n"; } } echo "<hr />"; echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>"; ?>[/code] Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948099 Share on other sites More sharing options...
mrMarcus Posted October 30, 2009 Share Posted October 30, 2009 try: wordwrap(nl2br(bbcode(strip_tags($post))), 70, '<br />') where 70 is whatever number of characters to display 'til the wrap. Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948102 Share on other sites More sharing options...
Noskiw Posted October 30, 2009 Author Share Posted October 30, 2009 Unfortunately, no effect again. I'm beginning to give up on php. Even the smallest of projects, I take them too far, when all I want to do is to succeed... Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948104 Share on other sites More sharing options...
Noskiw Posted October 30, 2009 Author Share Posted October 30, 2009 Nevermind. Thank you so much. This is something i have been struggling with for quite a while now. I had to make an extra comma "," and put "true" there without the quotation marks. I read the php.net manual. It turns out that it can be very useful after all... Thank you. If there was good rep in this forum, i would give you thousands of it. Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948106 Share on other sites More sharing options...
mrMarcus Posted October 30, 2009 Share Posted October 30, 2009 change this: nl2br(bbcode(strip_tags($new . "<br />"))) to: wordwrap(nl2br(bbcode(strip_tags($post))), 70, '<br />', true) lose these two lines: $text = $post; $new = wordwrap($text, 50, "<br />", true); Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948107 Share on other sites More sharing options...
Mchl Posted October 30, 2009 Share Posted October 30, 2009 nl2br(wordwrap()) not wordwrap(nl2br()) wordwrap adds newlines (\n\r) and nl2br replaces them with < br/> tags. If you do nl2br before wordwrap, you will not see any effect. [edit] Oh... @mrMarcus you're specyfing the newline in wordwrap itself. So nl2br should not be necessary at all. Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948108 Share on other sites More sharing options...
mrMarcus Posted October 30, 2009 Share Posted October 30, 2009 Oh... @mrMarcus you're specyfing the newline in wordwrap itself. So nl2br should not be necessary at all.nl2br() would still be necessary to maintain integrity of the original post i would believe. otherwise, the \n's that are created within a textarea or drawn from the db would not be converted to proper line-breaks (<br />) for normal display on a page. normally speaking, you are correct in that most cases wordwrap() and nl2br() are not needed together. Link to comment https://forums.phpfreaks.com/topic/179689-solved-need-a-line-break-after-a-certain-amount-of-characters/#findComment-948117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.