Forum Moderators: coopster

Message Too Old, No Replies

Accept Enter Key in a PHP

Accept Enter Key in a PHP

         

BenySay

9:35 pm on Jan 24, 2004 (gmt 0)

10+ Year Member



I have a form + a send program to send text in a row in mySQL. This is work fine, so when you add some enter key, the <br> is not send to the data base, and all the text is writin on the same line. I have to use de <br> command to do that, so this is not very friendly for the end user. Any Ideas? ( here, in this forum, it's look to work ...
You know how I can do that? )
( My database row is set to FULL TEXT )

BitBanger

9:59 pm on Jan 24, 2004 (gmt 0)

10+ Year Member



Assuming the text is extracted from the database as $text, the following will display it


$text = htmlentities($text);
echo '<p>'.ereg_replace("(\r\n¦\r¦\n)","</p><p>",$text).'</p>';

I'm not a regular expression expert, but I think the above should match a newline regardless of the client machine.

What this is supposed to do is to replace all occurences of a newline with paragraph tags.
The first line also protects you from people entering HTML code in the text field.

BenySay

10:41 pm on Jan 24, 2004 (gmt 0)

10+ Year Member



I'm trying a couple of way to add your lines, didn't work, so where I have to place it, here is my code :

# START THE TABLE INFORMATION FOR THE RESULTING INFORMATION
echo '<table cellpadding=0 spacepadding=0 border=1 bordercolor="#FFFFFF" width=100%><tr>';
# BEGIN THE SQL QEURY FOR THE INFORMATION
# SHOW ALL THE CONTENTS
$result=mysql_db_query($base,"select * from ".$basesites." WHERE `id` = '2'",$link);
if ($result > 0)
{
$num4=mysql_num_rows($result);
if($num4!=0)
{
$n=0;
while ( $n<$num4 )
{
# call and show the date
$date=mysql_result($result,$n,"date");
# call and show the tilte
$title=mysql_result($result,$n,"title");
# call and show the vedette
$vedette=mysql_result($result,$n,"vedette");
# call and show the text
$text=mysql_result($result,$n,"text");
# call and show the sit url
$genre=mysql_result($result,$n,"genre");
# call and show the sit url
$age=mysql_result($result,$n,"age");
# call and show the sit url
$site=mysql_result($result,$n,"site");
# call and show the sit url
$image_site=mysql_result($result,$n,"image_site");




$n++;
if (!$size) $size="0 kb";

echo "<tr bgcolor=709C9D><div align=right><font color=#FFFFFF size=-1><b>$date</b></font></div></tr>";
echo "<tr><div align=left><font color=#000000 size=-1><strong>$title</strong></font></div></tr>";
echo "<tr><div align=left><font color=#000000><BR>$vedette</font></div></tr>";
echo "<tr><div align=left><font color=#000000><BR>$text</font></div></tr>";
echo "<br><tr><div align=left><font color=#000000>$genre<br><br><img src=$age width=25 height=25>&nbsp;&nbsp;<a href=$site target=_blank><img src=$image_site width=100 height=25 border=0></a></font></div></tr>";

}
}
echo "</table>";
}

coopster

11:37 pm on Jan 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Will the nl2br [php.net] function work for you?

BitBanger

3:55 am on Jan 25, 2004 (gmt 0)

10+ Year Member



What happened? Did you get an error message, or garbled output?

Is the field you are having problems with named text?

Assuming it is, then right after

$text=mysql_result($result,$n,"text");

add

$text = '<p>'.ereg_replace("\n","</p><p>",$text).'</p>';

This should do what you want.

I simplified the search expression to eliminate potential errors.

BenySay

10:16 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



Great! It's working fine ... I'm using this :
$text = '<p>'.ereg_replace("\n"," ",$text).'</p>';

I just removed the <p></p> from your code the eliminited the surplus blank lines and it's perfect!

Thanks to you BitBanger

BenySay

11:00 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



Exactly, I'm using this :
$text = '<p>'.ereg_replace("\n","<br>",$text).'</p>';

Thanks for your help.