PHP Show How To Format Font Characters As They Are Submitted By Forms
RegisterLogin
PHP Show How To Format Font Characters As They Are Submitted By Forms
Post Description: PHP Show How To Format Font Characters As They Are Submitted By Forms
Tags: PHP, Show, How, To, Format, Font, Characters, As, They, Are, Submitted, By, Forms
This Post Was Posted On Feb 29, 2008 By pinguin #1887
Post Description: PHP Show How To Format Font Characters As They Are Submitted By Forms
Tags: PHP, Show, How, To, Format, Font, Characters, As, They, Are, Submitted, By, Forms
This Post Was Posted On Feb 29, 2008 By pinguin #1887
PHP Show How To Format Font Characters As They Are Submitted By Forms by pinguin
to explain better what i am talking about, lets say i have a web form with a text area, the text area asks for the user's comments. so lets say my comments are as follows:
Quote:
Hi, I am writing this short paragraph, this is the first line.
This is the second line of the paragraph
I skipped line 3 and started on line 4
This is line 5 now
Line 6 is the end of my paragraph
This is the second line of the paragraph
I skipped line 3 and started on line 4
This is line 5 now
Line 6 is the end of my paragraph
now when you enter the data into mysql database and you retrieve it from your table and display it on your web page this is how it comes out:
Quote:
Hi, I am writing this short paragraph, this is the first line. This is the second line of the paragraphI skipped line 3 and started on line 4 This is line 5 now Line 6 is the end of my paragraph
As you can see, its all together without any line breaks, it doesn't show the return (enter) keystrokes and it show all in one line. I wrote up a little script to show how you can write a PHP code to display the content as it is entered in the form from the user.
first, open your text editor, i am using windows xp, so i will be using notepad. so if you are using windows open a new notepad and copy and paste the following code:
Code:
<?
########################################################################################
############## THIS SCRIPT WAS WRITTEN BY WWW.WEBUNE.COM SUPPORT #######################
############## PHP HOSTING PROVIDED BY HTTP://WWW.WEBUNE.COM #######################
########################################################################################
?>
<html>
<head>
<title>How to show the real text entered in a form by wallpaperama</title>
</head>
<body>
<?
$format_textfield = mysql_real_escape_string($_POST[textfield]);
$format_textfield = str_replace("\r\n",'<br>',$format_textfield);
?>
<strong>How to show the real text entered in a form by wallpaperama <a href="http://www.wallpaperama.com">WALLPAPERAMA.COM</a></strong>
<HR>
<strong><em>Formatted Text:</em></strong><br>
<br>
<? echo $format_textfield; ?><br><hr>
<form name="form1" method="post" action="">
<p>Enter A Paragraph Here:<br>
<textarea name="textfield" cols="35" rows="5"><? echo htmlspecialchars($textfield); ?></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<div align="center">PHP hosting by <a href="http://www.webune.com">Webune.com</a></div>
</body>
</html>
########################################################################################
############## THIS SCRIPT WAS WRITTEN BY WWW.WEBUNE.COM SUPPORT #######################
############## PHP HOSTING PROVIDED BY HTTP://WWW.WEBUNE.COM #######################
########################################################################################
?>
<html>
<head>
<title>How to show the real text entered in a form by wallpaperama</title>
</head>
<body>
<?
$format_textfield = mysql_real_escape_string($_POST[textfield]);
$format_textfield = str_replace("\r\n",'<br>',$format_textfield);
?>
<strong>How to show the real text entered in a form by wallpaperama <a href="http://www.wallpaperama.com">WALLPAPERAMA.COM</a></strong>
<HR>
<strong><em>Formatted Text:</em></strong><br>
<br>
<? echo $format_textfield; ?><br><hr>
<form name="form1" method="post" action="">
<p>Enter A Paragraph Here:<br>
<textarea name="textfield" cols="35" rows="5"><? echo htmlspecialchars($textfield); ?></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<div align="center">PHP hosting by <a href="http://www.webune.com">Webune.com</a></div>
</body>
</html>
once you have paste this code into your text editor, save as format.php and upload to your website. NOTE: you MUST have PHP on your website, if you don't have PHP, you can visit our friends at www.webune.com and signup with one of their popular PHP plans.
open format.php with your browser once you have uploaded to your site. you will be presented with a form. enter a paragraph with line breaks and you will see it formatted exactly as it was entered. this is a simple text editor script code in php you can use to learn how you can apply it to your website, it shows the basic on how to do make a simple to use text editor into your web forms.
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
hostman
#2122 1
you can check out this post its good information:
http://www.wallpaperama.com/forums/another-way-to-use-mysql-real-escape-string-instead-trimstripslashes-t5712.html
http://www.wallpaperama.com/forums/another-way-to-use-mysql-real-escape-string-instead-trimstripslashes-t5712.html
Feb 10, 2008 Reply Report abuse
hostman
#2121 2
wow, thanks, i never knew about this function. it works
here's my example:
<?php
echo nl2br("this is line1 n and this is line2 ");
?>;
this is the outpu:
this is line1
and this is line2
so basically nl2br() Returns string with '
' inserted before all newlines, so it changes the n to
or
with is the return charrage or charracter for in hmtl.
here's my example:
<?php
echo nl2br("this is line1 n and this is line2 ");
?>;
this is the outpu:
this is line1
and this is line2
so basically nl2br() Returns string with '
' inserted before all newlines, so it changes the n to
or
with is the return charrage or charracter for in hmtl.
Jun 19, 2007 Reply Report abuse
Marc
#2120 3
thanks for the script, but i would recommend the use of the nl2br() function.
it worked for me:
php.net/manual/en/function.nl2br.php
it worked for me:
php.net/manual/en/function.nl2br.php
Jun 18, 2007 Reply Report abuse
Leave Your Comments...
©2012 Webune Forums - Sat Dec 15, 2012 5:57 pm
Powered by: Webune Forums V3
Powered by: Webune Forums V3