Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: problem z edycja newsow / znak konca linii
Forum PHP.pl > Forum > PHP
odis
Witam. Mam mały problem z panelem administracyjnym portalu który buduje.
Podczas dodawania newsa wszystko jest w porządku, natomiast problemy się zaczynają kiedy chcę jakiegokolwiek edytować.
Newsy znajdują się w bazie danych. Kiedy ręcznie w bazie wyedytuje dany tekst usuwając wszystkie "entery" edycja działa prawidłowo. Jeżeli jakiś news posiada jednak enter w bazie danych wtedy nie wczytuje mi się poprawnie do skryptu...
Oto kod całości:
Kod
   if($strona =='edytuj_news')
   {
       $id=$_GET['id'];
       include("baza.php");
       $link=mysql_query("SELECT * FROM newsy WHERE id='$id'");
       $wiersz=mysql_fetch_array($link);
  
        echo '<p><form method="POST" action="index.php?strona=wyedytuj_news&id='.$wiersz['id'].'" onsubmit="return submitForm();">
           <table border="0" width="100%">
               <tr>
                   <td>Tytul:</td>
                   <td><input type="text" name="tytul" size="64" value="'.$wiersz['tytul'].'"></td>
               </tr>
               <tr>
                   <td>Tresc: </td>
                   <td>';
                   ?>
                   <script language="JavaScript" type="text/javascript">
   <!--
   function submitForm() {
       //make sure hidden and iframe values are in sync for all rtes before submitting form
       updateRTEs();
      
       //change the following line to true to submit form
       alert("tekst = " + (document.RTEDemo.tekst.value));
       return false;
   }
  
   //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML, encHTML)
   initRTE("panel/images/", "panel/", "", true);
   //-->
   </script>
   <noscript><p><b>Javascript musi być włączona.</b></p></noscript>
  
   <script language="JavaScript" type="text/javascript">
   <!--
   //build new richTextEditor
   var tekst = new richTextEditor('tekst');
   tekst.html = '<?php echo $wiersz[tekst]; ?>';
  
   //enable all commands for demo
   tekst.cmdFormatBlock = true;
   tekst.cmdFontName = true;
   tekst.cmdFontSize = true;
   tekst.cmdIncreaseFontSize = true;
   tekst.cmdDecreaseFontSize = true;
  
   tekst.cmdBold = true;
   tekst.cmdItalic = true;
   tekst.cmdUnderline = true;
   tekst.cmdStrikethrough = true;
   tekst.cmdSuperscript = true;
   tekst.cmdSubscript = true;
  
   tekst.cmdJustifyLeft = true;
   tekst.cmdJustifyCenter = true;
   tekst.cmdJustifyRight = true;
   tekst.cmdJustifyFull = true;
  
   tekst.cmdInsertHorizontalRule = true;
   tekst.cmdInsertOrderedList = true;
   tekst.cmdInsertUnorderedList = true;
  
   tekst.cmdOutdent = true;
   tekst.cmdIndent = true;
   tekst.cmdForeColor = true;
   tekst.cmdHiliteColor = true;
   tekst.cmdInsertLink = true;
   tekst.cmdInsertImage = true;
   tekst.cmdInsertSpecialChars = true;
   tekst.cmdInsertTable = true;
   tekst.cmdSpellcheck = true;
  
   tekst.cmdCut = true;
   tekst.cmdCopy = true;
   tekst.cmdPaste = true;
   tekst.cmdUndo = true;
   tekst.cmdRedo = true;
   tekst.cmdRemoveFormat = true;
   tekst.cmdUnlink = true;
  
   tekst.toggleSrc = true;
  
   tekst.build();
   //-->
   </script>
                   <?php
                   echo'
                   </td>
               </tr>
              
               ';
               if($wiersz['obc']==1)
               echo'
               <tr>
                   <td>Obcinanie kodu ?
                   <input type="radio" name="obc" value="0"> Nie</td>
                   <td><input type="radio" name="obc" value="1" checked> Tak</td>
                   </tr>
               <tr>
              
               ';
               if($wiersz['obc']==0)
               echo'
               <tr>
                   <td>Obcinanie kodu ?
                   <input type="radio" name="obc" value="0" checked> Nie</td>
                   <td><input type="radio" name="obc" value="1"> Tak</td>
                   </tr>
               <tr>
               <tr>
                   <td> </td>
                   <td><input type="submit" value="EDYTUJ" /></td>
               </tr>
           </table>
       </form>';
       function rteSafe($strText) {
       $tmpString = $strText;
      
       $tmpString = str_replace(chr(145), chr(39), $tmpString);
       $tmpString = str_replace(chr(146), chr(39), $tmpString);
       $tmpString = str_replace("'", "'", $tmpString);
      
       $tmpString = str_replace(chr(147), chr(34), $tmpString);
       $tmpString = str_replace(chr(148), chr(34), $tmpString);
  
       $tmpString = str_replace(chr(10), " ", $tmpString);
       $tmpString = str_replace(chr(13), " ", $tmpString);
      
      
       return $tmpString;
   }
   }
  
   if(isset($_GET['strona']) && $_GET['strona']=='wyedytuj_news' && isset($_GET['id']))
   {
       $tytul=$_POST['tytul'];
       $tekst=$_POST['tekst'];
       $obc=$_POST['obc'];
       $id=$_GET['id'];
   include("baza.php");
       mysql_query("UPDATE newsy SET tytul='$tytul', tekst='$tekst', obc='$obc' WHERE id='$id'");
       echo 'Pomyslnie wyedytowalem newsa!
    Jego nowy tytul to: <b>'.$tytul.'</b>, a tresc: <b>'.$tekst.'</b>';
  
   }


Jak i co należy zmienić aby znaki końca linii nie były zapisywane do bazy, lub aby były usuwane zaraz po wczytaniu z bazy przed wyświetleniem ?
JoShiMa
Ale w czym Ci te znaki koca linni przeszkadzają. Jesli wprowadzasz tekst z enterami to czemu potem nie chcesz, żeby były w bazie?

Możesz użyć str_replace() żeby je usunąć z tekstu, albo nl2br(), żeby je zamienić na <br>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.