0

Okay I have a textarea that edits a text div.
When the user edits the text and submits,
paragraphs and line breaks are passed to the div.

i.e (not the browser)text div after submit....

'WARNING - This email and any attachments may be private & confidential.

If received in error, please delete and inform us by return email.'

textarea after submit....


'WARNING - This email and any attachments may be private & confidential. If received in error, please delete and inform us by return email.'

So the question is how can I get those paragraphs and breaks stored
and retrieved from a Mysql database, when using strip tags?

snippet that makes html tags for new lines..

$text = $row['text'];
$headline = $row['headline'];

// Use \n for newline on all systems
$text = preg_replace("/(\r\n|\n|\r)/", "\n", $text);

// Only allow two newlines in a row.
$text = preg_replace("/\n\n+/", "\n\n", $text);

// Put <p>..</p> around paragraphs
$text = preg_replace('/\n?(.+?)(\n\n|\z)/s', "<p>$1</p>", $text);

// Convert newlines not preceded by </p> to a <br /> tag
$text = preg_replace('|(?<!</p>)\s*\n|', "<br />", $text);

snippet that echos database info and strips the html

<textarea rows="10" cols="50" name="text">
<?php
echo strip_tags($text);
?>
</textarea>

how the info is updated....

$self = $_SERVER['PHP_SELF'];
if ($_POST['text_id']) { $text_id=$_POST['text_id']; }
if ($_POST['headline']) { $headline=$_POST['headline']; }
if ($_POST['text']) { $text=$_POST['text']; }

$tbl_name = "text_boxes";
$text_id = "27";
if ($logged_in=='true'){
$sql="UPDATE $tbl_name SET headline ='".$headline."', text='".$text."' WHERE text_id = '".$text_id."'";
$result=mysql_query($sql);

Any Ideas? H :^)

3
Contributors
11
Replies
14
Views
7 Years
Discussion Span
Last Post by harry_watson
0

Hey thanks for that but in my text field I still get...

<p><p>WARNING - This email and any attachments may be private & confidential.</p><p>another paragraph etc...<br />another
line break etc....

So I'm trying to get those tags out of the text field and what they do in.

Thanks tho... :^)

0

By the way, nice function wasn't aware of it.
What's happening is that line breaks and paragraphs
are posted from the text field to the text div as
html tags then echoed and the tags stripped out.

so the text field reads; paragraph,paragraph
and without strip_tags; <p>paragraph</p><p>paragraph</p>

Both ways post to the text div as;

paragraph

paragraph

Which is how I'd like my text field to look and behave.

:^) H

0

Why don't you use strip_tags like the following?

$input='input<br><b>string</b>';
strip_tags($input,'<p><br>');

That will strip every tag except the <p> and <br> tags. I believe that is the solution to your problem...

0

Maybe if you nl2br() it before it goes into the db

if ($_POST['text']) { $text=nl2br($_POST['text']); }

then when you want to echo it

$text = strip_tags($text);
echo $text;

That worked fine for me...

0

But we need a code that will reverse what has been posted
and then selected from and to the database.

The text area posts carrige returns and line breaks to the database
and spits all that into the text div. The tags you suggest I keep are the ones I want to get rid of they will just appear as <p>paragraph</p>.

I'm looking for output - or update to a text field where html tags are output to a textarea just like

this

not like<br />this

I may be barking up the wrong tree but I've done some solid code on this and appreciate your input and output, He He :^) Thanks to date().

0

I'll try that when I get my eyeballs out from the keyboard. Thanks. :^)

Maybe if you nl2br() it before it goes into the db

if ($_POST['text']) { $text=nl2br($_POST['text']); }

then when you want to echo it

$text = strip_tags($text);
echo $text;

That worked fine for me...

0

The only problem with inserting the <p> tags is that unless there are two blank lines to represent a removed <p> tag then it would be impossible to reverse because how would the computer know where to insert these tags? It is best not to strip them in the first place.

But we need a code that will reverse what has been posted
and then selected from and to the database.

The text area posts carrige returns and line breaks to the database
and spits all that into the text div. The tags you suggest I keep are the ones I want to get rid of they will just appear as <p>paragraph</p>.

I'm looking for output - or update to a text field where html tags are output to a textarea just like

this

not like<br />this

I may be barking up the wrong tree but I've done some solid code on this and appreciate your input and output, He He :^) Thanks to date().

0

The only problem with inserting the <p> tags is that unless there are two blank lines to represent a removed <p> tag then it would be impossible to reverse because how would the computer know where to insert these tags? It is best not to strip them in the first place.

Maybe I forget strip tags and use css

#textarea <p>, <br />,
{
display: none;
}

Good thinking, thanks very much, I'll give it a go in the morning. :^)

0

solved!!!!! This could be really useful to someone out there.
Text area displays

So what if I want to type in this area and apply
changes below.

Make a new line and edit my text some more.

text div displays

So what if I want to type in this area and apply
changes below.

Make a new line and edit my text some more.

text area code (it displays literally, so any whitespace in the code will show in the textarea)

<textarea rows="10" cols="70" name="text" class="text_edit"><?php
$text = preg_replace('/</','
<',$text);
$text = preg_replace('/>/','
>',$text);
$desc = html_entity_decode(strip_tags($text));
$desc = preg_replace('/[\n\r\t]/',' ',$desc);
$desc = preg_replace('/  /',' ',$desc); 
$text = preg_replace('/\r/',' ',$text); 
echo strip_tags($text); 
?></textarea>
0

solved!!!!! This could be really useful to someone out there.
Text area displays

So what if I want to type in this area and apply
changes below.

Make a new line and edit my text some more.

text div displays

So what if I want to type in this area and apply
changes below.

Make a new line and edit my text some more.

text area code (it displays literally, so any whitespace in the code will show in the textarea)

<textarea rows="10" cols="70" name="text" class="text_edit"><?php
$text = preg_replace('/</','
<',$text);
$text = preg_replace('/>/','
>',$text);
$desc = html_entity_decode(strip_tags($text));
$desc = preg_replace('/[\n\r\t]/',' ',$desc);
$desc = preg_replace('/  /',' ',$desc); 
$text = preg_replace('/\r/',' ',$text); 
echo strip_tags($text); 
?></textarea>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.