oliden Posted February 3, 2007 Share Posted February 3, 2007 I have a problem and it is that whens people add coments and if they put a long word it destroys my web layout this is the script: can anyone help? ??? for it to work you have to make a review folder beside <?php extract($HTTP_GET_VARS); extract($HTTP_POST_VARS); $ip = getenv(REMOTE_ADDR); //censored words $name = str_replace ("|~|","", $name); $comment = str_replace ("\n", "<br>", $comment); $comment = str_replace ("|~|", "-", $comment); $comment = str_replace ("fuck", "-", $comment); $comment = str_replace ("suck", "-", $comment); $comment = str_replace ("jackass", "-", $comment); $comment = str_replace ("bitch", "-", $comment); $comment = str_replace ("asshole", "-", $comment); $today = date("D M:d:Y"); $ficdest=explode(".",basename($PHP_SELF)); $mfile="review/".$ficdest[0].".txt"; if(file_exists($mfile)) { }else{ $m_compteur=fopen($mfile, "w"); fclose($m_compteur); } $max_file_size_m = 20; $file_size_m= filesize($mfile); $log_size_m = $file_size_m/1024; if (strlen($name)>="1" && strlen($comment)>="1"){ if(file_exists($mfile)) { $compteur=fopen($mfile, "a+"); fputs ($compteur, " |~|"); fputs ($compteur, "$name"); fputs ($compteur, "|~|"); fputs ($compteur, "$comment"); fputs ($compteur, "|~|"); fputs ($compteur, "$today"); fputs ($compteur, "|~|"); fputs ($compteur, "\n"); fclose($compteur); echo "<FONT COLOR=\"#0000FF\">Your Review has been added.</FONT>"; }else{ $n_compteur=fopen($mfile, "w"); fputs ($n_compteur, "|~|"); fputs ($n_compteur, "$name"); fputs ($n_compteur, "|~|"); fputs ($n_compteur, "$comment"); fputs ($n_compteur, "|~|"); fputs ($n_compteur, "$today"); fputs ($n_compteur, "|~|"); fputs ($n_compteur, "\n"); fclose($n_compteur); echo "<FONT COLOR=\"#0000FF\">Your Review has been added.</FONT>"; } } if ($log_size_m > $max_file_size_m) { $folename = "$mfile"; $fd = fopen ($folename, "r"); $puff = fread ($fd, filesize($folename)); fclose ($fd); $last_file = fopen ("rev.txt", "a+"); fwrite ($last_file, $puff); fclose($last_file); $fz = fopen ($mfile, "w"); fwrite ($fz, ""); fclose($fz); $flowname = "rev.txt"; $fd1 = fopen ($flowname, "r"); $stiff = fread ($fd1, filesize($flowname)-1024); fclose ($fd1); $fm100 = fopen ($mfile, "a+"); fwrite ($fm100, $stiff); fclose ($fm100); $fy100 = fopen ("rev.txt", "w"); fwrite ($fy100, ""); fclose($fy100); } $main_file_m = $mfile; $latest_rev = 6; //Number of latest reviews to show $lines_review = file($main_file_m); $abc = count($lines_review); $uli = $abc - $latest_rev; echo "<center><table width=500 border=1 bordercolor=#808080 cellspacing=0 cellpadding=2>"; for($cv = $abc; $cv >= $uli ;$cv--){ if(substr($lines_review[$cv], 0, 6 )==""){ $lpop = explode("|~|",$lines_review[$cv]); echo "<tr bgcolor=#ccccc><td>$lpop[1] Reviewed on $lpop[3]:</td></tr><tr><td bgcolor=#eaeaea> $lpop[2] </td></tr>"; } } ?> </table> <form method='post'> <table width='500' border='1' bordercolor='#808080' cellspacing='0'> <tr bgcolor='#ccccc'><b><font size=1> <td><b>Add a Review</b></td></tr> <tr><td><table border='1' bordercolor='#ffffff' cellspacing='0'> <tr><td><font size=1> Name:<BR></font></b></td><td><input type='text' maxlength="50" name='name' size=20 style="font-weight:10"></td></tr> <tr valign='top'><td><font size=1> Message:<BR></b></td> <td><textarea cols='35' rows='4' name='comment' onkeydown=textCounter(this.form.comment,this.form.descriptionleft,400); onkeyup=textCounter(this.form.comment,this.form.descriptionleft,400);></textarea><br>Characters Left <INPUT maxLength=3 name=descriptionleft readOnly size=3 tabIndex=400 value=400> </td></tr> <tr><td></td><td> <input type='submit' value='Add Review' style="background:#cdc8bd;border-width:1;Border-color:#cdc8bd;"></td></tr> </table> </table> </form> </font><HR><FONT face=arial SIZE="1" COLOR="#00000">Powered By: <A HREF="http://www.ScriptsEz.net" target=_new>Unique Review</A></FONT></center> <?php ?> Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted February 3, 2007 Share Posted February 3, 2007 If the longest word is longer than the table cell width, then it will always readjust - theres nothing you can stop it. I suppose you could check the length of each word and if it is longer than a set amount, explode it into two bits and put /n in there. I have no idea how to or if it would work. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 3, 2007 Share Posted February 3, 2007 use the wordwrap function. http://www.php.net/wordwrap You will be particularly interested in the fourth parameter, of which the manual says: If the cut is set to 1, the string is always wrapped at the specified width So, you would use: echo '<td>' . wordwrap($potentially_long_word, 40, "<br />", 1) . '</td>'; Quote Link to comment 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.