Solved

Remove line breaks from textarea

Posted on 2010-09-14
5
735 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

708 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

13 Experts available now in Live!

Get 1:1 Help Now