Solved

Remove line breaks from textarea

Posted on 2010-09-14
5
736 Views
Last Modified: 2012-05-10
Is there a way to remove the linke breaks which appear in internet explorer after the output of the textarea?
<textarea cols="90" rows="6" name="content"><!- START --><iframe width="400" height="250" src="http://maps.google.com/maps/api/staticmap?center=<?php echo $attorneysStuff['bizAddr'];?>,<?php echo $attorneysStuff['bizCity'];?>,<?php echo $attorneysStuff['bizState'];?>&zoom=14&size=400x250&maptype=roadmap&markers=color:blue|label:S|<?php echo $attorneysStuff['bizAddr'];?>,<?php echo $attorneysStuff['bizCity'];?>,<?php echo $attorneysStuff['bizState'];?>&sensor=false"></iframe><br><a href="<?php  session_start();echo $_SESSION['bizurl']; ?>"><?php echo $attorneysStuff['bizName'];?></a><!- END -->

</textarea>

Open in new window

0
Comment
Question by:seopti
5 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 33679226
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33679227
If you are looking for how to remove line breaks using javascript, then
http://www.textfixer.com/tutorials/javascript-line-breaks.php

document.getElementById("textArea1").value will give you the value of TextArea given that its id is textArea1.
0
 
LVL 5

Accepted Solution

by:
bupper earned 500 total points
ID: 33679330
Here is a good little script you can use for a PHP function (put this in your file before your textarea):
<?php
function stripJunk ($value) {
    // this will trim junk from strings, such as TAB, NEWLINE, NULL, and more
    $value = str_replace(str_split("\x0b\t\x00\r\n\\"), '', $value);
   
    // strip whitespace and other trash from beginning/end
    $value = trim($value);
   
    return $value;
}
?>

Then when you are outputting the data to your textarea, use something like:
<?php echo stripJunk($attorneysStuff['bizAddr']);?>
0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 33684431
Hai,

1) When storing DB itself use "nl2br" PHP function to store the text

2) When there is display can just print the html code or use the "str_replace" function to replace the break tag.


Thanks
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 33690759
You can use trim() to remove whitespace from the front and back of a string.
http://us3.php.net/manual/en/function.trim.php

You can use the REGEX example#5 shown here to strip excessive whitespace.
http://us3.php.net/manual/en/function.preg-replace.php

I would escape the cleaned-up string and store it in the data base.  When I am ready to produce output to the browser, I would take the string out of the data base, run it through htmlentities() to prevent bad stuff going to a client machine, and then use nl2br() to produce the appropriate line spacing.

HTH, ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

939 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now