text wraping on a long word

Discussion in 'PHP' started by oliden, Feb 2, 2007.

?

php long word wraping

  1. php long word wraping

    0 vote(s)
    0.0%
  2. php long word wraping

    0 vote(s)
    0.0%
  3. php long word wraping

    0 vote(s)
    0.0%
  4. php long word wraping

    2 vote(s)
    100.0%
  1. #1
    I have the folowing php script, not made by me but there is one thing that is failing on it and that is wen some one puts a long word in the comment box it basicly destroys my web page.
    Does any one know how to fix this problem on this scrip?:confused: :confused: :confused:
    Many thanks anyway to anyone who can help me.;)

    you have to make a folder callet review and a rev.txt in there for it to work.



    <?php
    //Copyright Sctiptsez.net
    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&nbsp;<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
          ?>
     
    oliden, Feb 2, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    I did some changes:

    
    <?php
    
    //Get varaibles
    extract($HTTP_GET_VARS);
    extract($HTTP_POST_VARS);
    
    $ip = getenv($_SERVER['REMOTE_ADDR']);
    
    //censored words
    $sensor_list = array('|~|','fuck','suck','jackass','bitch','asshole');
    
    $comment = str_replace ($sensor_list,'', nl2br($_POST['comment']));
    
    $today = date("D M:d:Y");
    
    $ficdest = explode(".",basename($_SERVER['PHP_SELF']));
    
    $mfile="review/".$ficdest[0].".txt";
    
    if(!file_exists($mfile)) {
    	$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, "[list]|~|");
    		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, "[list]|~|");
    		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 )=="[list]"){
    $lpop = explode("|~|",$lines_review[$cv]);
    $lpop[2] = wordwrap($lpop[2],20,' ');
    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&nbsp;<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
    ?>
    Reply With Quote
    
    PHP:
    If it doesn't work, just use your old code and add:

    
    $lpop[2] = wordwrap($lpop[2],20,' ');
    
    PHP:
    ontop of:

    
    echo "<tr bgcolor=#ccccc><td>$lpop[1] Reviewed on $lpop[3]:</td></tr><tr><td bgcolor=#eaeaea> $lpop[2] </td></tr>";
    
    PHP:
    Peace,
     
    Barti1987, Feb 2, 2007 IP
  3. oliden

    oliden Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi I have the answer!!!

    $lpop[2] = wordwrap($lpop[2],20,' ');

    This didn't quite doo the job but I swaped it for

    $lpop[2] = wordwrap($lpop[2], 34, "\n", 1);

    and it does magic, it works perfectly, it forces a space betwen every word longer than 34 letters.

    Thankyou azizny you have been big help, and have done a loveley job with it.

    Here is a final post of the script fixed for all you that dont realy understand so much.

    <?php
    //Get varaibles
    extract($HTTP_GET_VARS);
    extract($HTTP_POST_VARS);
    $ip = getenv($_SERVER['REMOTE_ADDR']);
    //censored words
    $sensor_list = array('|~|','fuck','suck','jackass','bitch','asshole');
    $comment = str_replace ($sensor_list,'', nl2br($_POST['comment']));
    $today = date("D M:d:Y");
    $ficdest = explode(".",basename($_SERVER['PHP_SELF']));
    $mfile="review/".$ficdest[0].".txt";
    if(!file_exists($mfile)) {
    $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]);
          $lpop[2] = wordwrap($lpop[2], 34, "\n", 1);
          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&nbsp;<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"><A HREF="" target=_new></A></FONT></center>
          <?php
          ?>

          Peace,
     
    oliden, Feb 3, 2007 IP
  4. giovanni

    giovanni Peon

    Messages:
    1,174
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What was the point of the poll?
     
    giovanni, Feb 3, 2007 IP