473,657 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting certain newlines to <br />s

I have a site wherein the clients can update the individual pages by editing
the text of that page in a <textarea>. Then, when the page is displayed,
all of the newlines (\n) are converted to HTML line breaks (<br />).
However, I have come across some instances where I do not want to convert
the newlines, such as the following:

<table>
<tr>
....
</tr>
</table>

Obviously, I would not want this to be

<table><br />
<tr><br />
....
</tr><br />
</table><br />

Can anyone suggest a method for achieving this? I've tried different
mixtures of regular expressions, but my skills with those are just not up to
par.

Christopher Finke
Jul 17 '05 #1
4 4552

"Christophe r Finke" <ch************ **@hotmail.com> wrote...

: Can anyone suggest a method for achieving this? I've tried different
: mixtures of regular expressions, but my skills with those are just not up
to
: par.

Christopher, first off it's never a good idea to allow people to enter html
code in forms of a content management service. You can allow them to insert
simple tags like <i>,<b> and <u> but if you're allowing them to create
things like tables it could seriously screw up the design of the site.

A practical solution for your problem would be to do a str_replace on the
text before you store it. For example:

$remove = array("<table>\ n", "<table>\r" , "<table>\r\ n");
$text = str_replace($re move, '<table>', $text);

see: http://www.php.net/str_replace

Hope it helps,
..soma
Jul 17 '05 #2
somaBoy MX wrote:
"Christophe r Finke" <ch************ **@hotmail.com> wrote...

: Can anyone suggest a method for achieving this? I've tried different
: mixtures of regular expressions, but my skills with those are just not up
to
: par.

Christopher, first off it's never a good idea to allow people to enter html
code in forms of a content management service. You can allow them to insert
simple tags like <i>,<b> and <u> but if you're allowing them to create
things like tables it could seriously screw up the design of the site.

A practical solution for your problem would be to do a str_replace on the
text before you store it. For example:

$remove = array("<table>\ n", "<table>\r" , "<table>\r\ n");
$text = str_replace($re move, '<table>', $text);

see: http://www.php.net/str_replace

Hope it helps,
.soma


Well, depending on how much work you want to do, which wouldn't be all
that much really, you could let them put tables in providing that you
check the syntax, running it through PHP's XML Parser actually may do
the trick, in the effort to make sure for every opening tag we have a
closing tag because tables are only really a pain in that scenario if
they close and don't open or such like.
~Cameron
Jul 17 '05 #3
On 2004-01-29, Christopher Finke <ch************ **@hotmail.com> wrote:
I have a site wherein the clients can update the individual pages by editing
the text of that page in a <textarea>. Then, when the page is displayed,
all of the newlines (\n) are converted to HTML line breaks (<br />).
However, I have come across some instances where I do not want to convert
the newlines, such as the following:

<table>
<tr>
...
</tr>
</table>

Obviously, I would not want this to be

<table><br />
<tr><br />
...
</tr><br />
</table><br />


I think that if you let them write <table> etc tags, they should be
aware of the fact that newlines don't show up the way they expect it
too.

If you use output buffering, you could run tidy before outputting the
lot.
--
http://home.mysth.be/~timvw
Jul 17 '05 #4
It can't be done. You either accept HTML as input or accept plain text. Your
computer can't resolve the ambiguity when you mix the two up.

Uzytkownik "Christophe r Finke" <ch************ **@hotmail.com> napisal w
wiadomosci news:bv******** ****@ID-158177.news.uni-berlin.de...
I have a site wherein the clients can update the individual pages by editing the text of that page in a <textarea>. Then, when the page is displayed,
all of the newlines (\n) are converted to HTML line breaks (<br />).
However, I have come across some instances where I do not want to convert
the newlines, such as the following:

<table>
<tr>
...
</tr>
</table>

Obviously, I would not want this to be

<table><br />
<tr><br />
...
</tr><br />
</table><br />

Can anyone suggest a method for achieving this? I've tried different
mixtures of regular expressions, but my skills with those are just not up to par.

Christopher Finke

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7860
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my "languages" files and these are describes for things on my website. Example text looks like this:
6
12151
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with you and see if there are any improvments that i should make ;-) It should be fast and if possible compatible with todays modern browser-standards. It should be activated by the onload-event. This is my code, free for all to use:
4
24263
by: lkrubner | last post by:
PHP has a function called nl2br() which takes all the newlines in a string and turns them into break tags <br>. I need to do the same in javascript. Is this about right? I'm not sure how one is supposed to reference invisible characters in Javascript strings. I took an example on the web and tried to modify it to my uses. function nl2br_js(myString) { var regX = /\n/gi ; s = new String(myString);
7
2739
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the Server.EncodeHTML does not do that it seems). The problem is that users can use a special tag when editing the top to specify an area of the tip that will...
2
2528
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all the charcontrols option and chr(13) with success.. was using the following code: Dim s As String = MyTextbox.Text
1
3168
by: Winshent | last post by:
I have a multi line text in an admin page on my cms. I am trying to capture carriage returns as and replace them with <p></p> bfore the string gets written to the database. I have tried all the charcontrols option and chr(13) with success.. was using the following code: Dim s As String = MyTextbox.Text
3
3367
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
7
3616
by: Nathan Sokalski | last post by:
Something that I recently noticed in IE6 (I don't know whether it is true for other browsers or versions of IE) is that it renders <br/and <br></br> differently. With the <br/version, which is what most people use when they write static code (some people use <br>, but with xhtml you are required to close all tags), IE6 simply breaks to the next line like it is supposed to. However, with <br></br>, which is what is sometimes generated by...
4
3825
by: ismailc | last post by:
Hi, I need help please. In <TD> certain length/max length then force <BR> I would like within a <TD> to allow certain amount of char and then force a <br>. Is this possible, Please Assist! Regards
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.