Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php] Gdzie jest nl2br?
Forum PHP.pl > Forum > Gotowe rozwi±zania
ADeM
Nie rozumiem tego.. w systemie newsów cutenews jest plik addnews.mdu a w nim:
  1. <?php
  2.  
  3. if($member_db[1] > 3){ msg(&#092;"error\", \"Access Denied\", \"You don't have permission to add news\"); }
  4. if ($action == &#092;"addnews\"){
  5.  
  6. $cat_lines = file(&#092;"./data/category.db.php\");
  7. echoheader(&#092;"addnews\", \"Add News\");
  8.  
  9. echo &#092;"
  10. <script LANGUAGE=&#092;"JavaScript\">
  11. function preview(){
  12. if(document.addnews.short_story.value == '' || document.addnews.title.value == ''){ alert('Your article must have at least Title and Short Story'); }
  13. else{
  14. dd=window.open('','prv','height=400,width=750,resizable=1,scrollbars=1')
  15. document.addnews.mod.value='preview';document.addnews.target='prv'
  16. document.addnews.submit();dd.focus()
  17. setTimeout(&#092;"document.addnews.mod.value='addnews';document.addnews.target='_self'\",500)
  18. }
  19. }
  20. onload=focus;function focus(){document.forms[0].title.focus();}
  21. </SCRIPT>
  22.  
  23. <table border=0 cellpading=0 cellspacing=0 width=\"654\" >
  24. <form method=post name=addnews action=\"$PHP_SELF\">
  25. <tr>
  26. <td width=\"75\">
  27. Tytu³ newsa
  28. <td width=\"575\" colspan=\"2\">
  29. <input type=text size=\"55\" name=\"title\" tabindex=1>
  30. </tr>\";
  31.  
  32. if($config_use_avatar == \"yes\"){
  33. echo\"<tr>
  34. <td width=\"75\">
  35. Zdjêcie które bêdzie ko³o opisu
  36. <td width=\"575\" colspan=\"2\">
  37. <input tabindex=2 type=text size=\"42\" value=\"$member_db[8]\" name=\"manual_avatar\" >&nbsp;&nbsp;&nbsp;<font style=\"font-size:7pt\">(optional)</font>
  38. </tr>\";
  39. }
  40.  
  41. if(count($cat_lines) > 0){
  42. echo\"<tr>
  43. <td width=\"75\">
  44. Category
  45. <td width=\"575\" colspan=\"2\">
  46. <select name=category tabindex=3>n
  47. <option value=\"\"> </option>n\";
  48. foreach($cat_lines as $single_line){
  49. $cat_arr = explode(\"|\", $single_line);
  50. $if_is_selected = \"\";
  51. if($category == $cat_arr[0]){ $if_is_selected = \" selected \"; }
  52. echo\"<option $if_is_selected value=\"$cat_arr[0]\">$cat_arr[1]</option>n\";
  53. }
  54. echo\"</select></tr>\";
  55. }
  56. echo\"<tr>
  57. <td width=\"75\" valign=\"top\">
  58. <br />Krótka wiadomo&para;æ:
  59. <td>
  60. <textarea rows=\"8\" cols=\"74\" name=\"short_story\" tabindex=4></textarea>
  61. <td width=\"108\" valign=\"top\">
  62. <p align=\"center\"><a href=# onclick=\"window.open('$PHP_SELF?&mod=images&action=quick&area=short_story', '_Addimage', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_Addimage\"><br />
  63. [dodaj zdjêcie]</a><br />
  64. <a href=# onclick=\"window.open('$PHP_SELF?&mod=about&action=cutecode&target=short_story', '_CuteCode', 'HEIGHT=280,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_Addimage\">[quick tags]</a><br />
  65. <br />
  66.  
  67. <script>
  68. function insertext(text,area){
  69. if(area==\"short\"){document.addnews.short_story.focus(); document.addnews.short_story.value=document.addnews.short_story.value +\" \"+ text; document.addnews.short_story.focus() }
  70. if(area==\"full\") {document.addnews.full_story.focus(); document.addnews.full_story.value=document.addnews.full_story.value +\" \"+ text; document.addnews.full_story.focus()}
  71. }
  72. </script>\";
  73.  
  74. echo insertSmilies('short', 4);
  75.  
  76. echo\"
  77. </tr>
  78.  
  79. <tr>
  80. <td width=\"75\" valign=\"top\">
  81. <br />Pe³na wiadomo&para;æ:<br /><font style=\"font-size:7pt\">(nieobowi&plusmn;zkowe)</font>
  82. <td>
  83. <textarea rows=\"12\" cols=\"74\" name=\"full_story\" tabindex=5></textarea>
  84. <td width=\"108\" valign=\"top\">
  85. <p align=\"center\"><br />
  86. <a href=# onclick=\"window.open('$PHP_SELF?mod=images&action=quick&area=full_story', '_Addimage', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_Addimage\">[dodaj zdjêcie]</a><br />
  87. <a href=# onclick=\"window.open('$PHP_SELF?&mod=about&action=cutecode&target=full_story', '_Addimage', 'HEIGHT=280,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_CuteCode\">[quick tags]</a><br />
  88. <br />\";
  89.  
  90. echo insertSmilies('full', 4);
  91.  
  92. echo\"
  93. </tr>
  94.  
  95. <tr>
  96. <td width=\"75\">
  97. <td width=\"575\" colspan=\"2\">
  98. <input type=submit value=\"  Dodaj Newsa  \" accesskey=\"s\">&nbsp;
  99. <input type=button value=\"Podgl&plusmn;d\" onClick=\"preview()\" accesskey=\"p\">&nbsp; <a href=\"javascript:ShowOrHide('options','')\">[opcje]</a>
  100. </tr>
  101.  
  102. <tr id='options' style='display:none;'>
  103. <td width=\"75\"><br>Options
  104. <td width=\"575\" colspan=\"4\">
  105. <br>
  106. <input style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_convert_new_lines\" checked> Zmieñ przej&para;cie do nastêpnej lini w newsie na &lt;br /&gt; (To zostawiæ tak jak jest)
  107. &nbsp;&nbsp;<br><input style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_use_html\" checked> U¿yj HTML'a w newsie
  108. </tr>
  109.  
  110. <input type=hidden name=mod value=addnews>
  111. <input type=hidden name=action value=doaddnews>
  112. </form>
  113. </table>\";
  114.  
  115. echofooter();
  116. }
  117. // *******************************************************************************
  118.  
  119. // Do add News to news.txt
  120. // *******************************************************************************
  121.  
  122. elseif($action == \"doaddnews\")
  123. {
  124.  
  125. if($if_convert_new_lines == \"yes\"){ $n_to_br = TRUE; }
  126. if($if_use_html == \"yes\"){ $use_html = TRUE; }
  127.  
  128. $full_story = replace_news(\"add\", $full_story, $n_to_br, $use_html);
  129. $short_story = replace_news(\"add\", $short_story, $n_to_br, $use_html);
  130. $title = replace_news(\"add\", $title, TRUE, $use_html);
  131.  
  132. if(trim($title) == \"\" or !$title){ msg(\"error\",\"B³&plusmn;d !!!\",\"Tytu³ nie zosta³ wpisany.\"\"javascript:history.go(-1)\"); }
  133. if(trim($short_story) == \"\" or !$short_story){ msg(\"error\",\"B³&plusmn;d !!!\",\"Nie wpisa³e&para;(a&para;) wiadomo&para;ci.\"\"javascript:history.go(-1)\"); }
  134.  
  135. $added_time = time()+ ($config_date_adjust*60);
  136. if($member_db[7] == 1){ $added_by_email = $member_db[5]; }
  137. else{ $added_by_email = \"none\"; }
  138.  
  139.  
  140. // Save The News Article In Active_News_File
  141.  
  142. $all_db = file(\"./data/news.txt\");
  143.  
  144. foreach($all_db as $news_line){
  145. $news_arr = explode(\"|\", $news_line);
  146. if($news_arr[0] == $added_time){ $added_time++; }
  147. }
  148.  
  149. $news_file = fopen(\"./data/news.txt\"\"w\");
  150. fwrite($news_file, \"$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$catego
    ry||n\");
  151. foreach ($all_db as $line){ fwrite($news_file, \"$line\");}
  152. fclose($news_file);
  153.  
  154. // Add Blank Comment In The Active_Comments_File
  155. $old_com_db = file(\"./data/comments.txt\");
  156. $new_com_db = fopen(\"./data/comments.txt\"\"w\");
  157. fwrite($new_com_db, \"$added_time|>|n\");
  158. foreach ($old_com_db as $line){ fwrite($new_com_db, \"$line\");}
  159. fclose($new_com_db);
  160.  
  161. // Incrase By 1 The Number of Written News for Current User
  162. $old_user_db = file(\"./data/users.db.php\");
  163. $new_user_db = fopen(\"./data/users.db.php\", w);
  164. foreach($old_user_db as $old_user_db_line){
  165. $old_user_db_arr = explode(\"|\", $old_user_db_line);
  166. if($username!=$old_user_db_arr[2]){
  167. fwrite($new_user_db,\"$old_user_db_line\");
  168. }
  169. else
  170. {
  171. $countplus = $old_user_db_arr[6]+1;
  172. fwrite($new_user_db,\"$old_user_db_arr[0]|$old_user_db_arr[1]|$old_user_db_arr[2]|$old_user_db_arr[3]|
    $old_user_db_arr[4]|$old_user_db_arr[5]|$countplus|$old_user_db_arr[7]|$old_user_
    db_arr[8]|$old_user_db_arr[9]||n\");
  173. }
  174. }
  175. fclose($new_user_db);
  176.  
  177. msg(\"info\",\"News Dodany\"\"Nowy news zosta³ dodany.\");
  178.  
  179. }
  180. ?>



I nigdzie tutaj nie ma wstawionego nl2br a do pliku zapisuje przejscie do nastepnej lini jako "<br />"... ja tez tak chce.... Czemu to zapisuje dobrze a nie ma nl2br...
peterj
  1. <?php
  2. if($if_convert_new_lines    == &#092;"yes\"){ $n_to_br        = TRUE; }
  3.     if($if_use_html                == &#092;"yes\"){ $use_html    = TRUE; }
  4.  
  5.     $full_story  = replace_news(&#092;"add\", $full_story, $n_to_br, $use_html);
  6.     $short_story = replace_news(&#092;"add\", $short_story, $n_to_br, $use_html);
  7.  
  8. ?>

Kod który tu doda³e¶ nie jest kompletny. Brak definicji wielu funkji, m.in. funkcji replace_news która jak widaæ pos³u¿y³a do zamiany "przejscia do nastepnej linii" na <BR />. Poszukaj w includach pliku z funkcjami.
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.