Solved

Remove line breaks from textarea

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Dialog Autoresize Bug 2 25
Test if unique ID is in log file 5 22
html border input line 7 16
I need help changing the colour of this image rollover please? 3 14
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

830 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