Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Locking table

Posted on 2003-11-18
4
Medium Priority
?
392 Views
Last Modified: 2013-12-13
I had successfull when inserting/viewing longtext data format from/in to mySQL database.
But i had a problem when viewing it in html table.
-No paragraph, write in 1 line only without braked line.
-The table width pushed by the text, then the table to be wider. (My page design damaged by that)

My question is :
1. How to locking the table width, so the text will automatically break lined ?
Inserting "<br>" text when inputting data in form textarea annoying me.
So, give me other solution.

2. How to prevent someone to not inserting html code to textarea form ?
Then, all text will be converted to text format.

I use this html form to send one paragraph of text :
<textarea name=news rows=60 cols=100%></textarea>

I use this php code to viewing $news :
print("<table width=50% border=0 cellpadding=0 cellspacing=0><tr><td>");
print("$news \n");
print("</td></tr></table>");
0
Comment
Question by:shanyuen
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:penguin3
ID: 9890115
Not sure what you mean by locking the table but under normal usage of text field I guess this line will solve both your problems if put before your print lines.
$news  = nl2br(htmlentities($news ));
0
 
LVL 5

Author Comment

by:shanyuen
ID: 9894631
Only question number 2 answered by that method.

This is what i means about my question (to locking table width) :

My client inserting 1 paragraph of text (many sentences) to text area form WITHOUT pressing enter button.

Then, NO new line created.

You know that my table width is 50%, long sentences (without new line) will stretching the table.

I had try this, but does'nt work.

print("<P>$news</P>");

  or

print("<PRE>$news</PRE>");

0
 
LVL 1

Accepted Solution

by:
penguin3 earned 1000 total points
ID: 9896517
I see.
Normally when posting to MySQL the linebrakes are in fact inserted but as \r\n and the nl2br-funcion converts them to <br />.
You can force a linebreak after a certain number och characters with the wordwrap function.

$news  = htmlentities($news);
$news = wordwrap($news, 50, "<br />");
0
 
LVL 5

Author Comment

by:shanyuen
ID: 9897814
It's work.
Thank You Very Much 100000x...
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question