kesha
Новичок
Проблема с переводом строки
код для записи:
код для вывода записи:
Знаю, что тут нехватает многих проверок, но меня интересует немного другое, как записать строку, чтобы НУЖНЫЕ переносы строки превратить в <br>? Ведь \n в конце строки, дает понять функции file(), что сл. строку нужно записать в новую ячейку массива.
З.Ы. не ругайте сильно, я только учусь
код для записи:
PHP:
<?php
$file ="news_db/news.txt";
setlocale(LC_ALL, '');
$date = strftime("%d %B %Y %H:%M %a ");
function add(){
global $file;
global $date;
$theme = $_REQUEST['theme'];
$author = $_REQUEST['author'];
$message = $_REQUEST['message'];
$theme = str_replace("|", "¦", $theme);
$author = str_replace("|", "¦", $author);
$message = str_replace("|", "¦", $message);
$message = trim($message);
$message = ereg_replace ("
", "<br>", $message);
$rec_array = file($file);
fclose(fopen($file, "a+b"));
$f = fopen($file, "a+t");
flock($f, LOCK_EX);
fwrite($f, "$date|$theme|$message|$author|\n");
fclose($f);
}
if (!isset($_REQUEST['doSave'])) {
?>
<table border=0 height="" width=180 cellspacing="0" cellpadding="0" bgcolor="black" align="center">
<tr>
<td width=20 height=20><p><img border="0" src="web_img/g1.jpg" width="20" height="20"></td>
<td width= height=20 background="web_img/pol_gor_v.jpg"></td>
<td width=20 height=20><p><img border="0" src="web_img/g2.jpg" width="20" height="20"></td>
</tr>
<tr>
<td width=20 background="web_img/pol_ver_l.jpg"></td>
<td width= height= bgcolor=#000000 valign="top">
<form action="<?=$_REQUEST['SCRIPT_NAME']?>" method="post">
<table border=0><tr><td>
<font color="white">Тема:</font></td>
<td><input type=text name="theme" value=""></td></tr>
<tr><td>
<font color="white">Автор:</font></td>
<td><input type=text name="author" value=""></td></tr>
<tr><td><font color="white">Новость:</font></td>
<td><textarea name="message" value=""></textarea></td></tr>
<tr><td colspan=2><input type=submit name="doSave" value="Добавить новость">
</td></tr>
</table>
</form>
</td>
<td width=20 background="web_img/pol_ver_r.jpg"></td>
<tr>
<td width=20 height=20><p><img border="0" src="web_img/g3.jpg" width="20" height="20"></td>
<td width= height=20 background="web_img/pol_gor_n.jpg"></td>
<td width=20 height=20><p><img border="0" src="web_img/g4.jpg" width="20" height="20"></td>
</tr>
</table>
</body>
</html>
<? } else {
add();
print "Новость успешно добавлена!";
}
?>
PHP:
<?php
function view() {
$file = "news/news_db/news.txt";
$mess_arr = file($file);
$mess_arr = array_reverse($mess_arr);
for ($i=0; $i<count($mess_arr); $i++) {
$msg = explode("|", $mess_arr[$i]);
print "<table border=0 height=\"\" width=\"400\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"black\" align=\"center\">
<tr>
<td width= height=><p><img border=\"0\" src=\"web_img/g1.jpg\" width=\"20\" height=\"20\">
</td>
<td width=20 height=20 background=\"web_img/pol_gor_v.jpg\">
</td><td width=20 height=20><img border=\"0\" src=\"web_img/g2.jpg\" width=\"20\" height=\"20\">
</td>
</tr>
<tr>
<td width=20 background=\"web_img/pol_ver_l.jpg\"></td>";
print"<td><table border=0 width=\"100%\" height\"100%\"><tr>
<td><font color=\"white\">$msg[0]</font></td></tr>";
print"<tr><td><font color=\"yellow\"><b>$msg[1]</b></font></td></tr>";
print"<tr><td><font color=\"white\">$msg[2]</font></td></tr>";
print"<tr><td align=\"right\"><font color=\"white\">Добавил: $msg[3]</font></td></tr></table></td>";
print"<td width=20 background=\"web_img/pol_ver_r.jpg\">
</td>
<tr><td width=20 height=20>
<img border=\"0\" src=\"web_img/g3.jpg\" width=\"20\" height=\"20\">
</td>
<td width= height=20 background=\"web_img/pol_gor_n.jpg\">
</td>
<td width=20 height=20>
<img border=\"0\" src=\"web_img/g4.jpg\" width=\"20\" height=\"20\">
</td>
</tr>
</table>";
}
}
view();
?>
З.Ы. не ругайте сильно, я только учусь
