Hi,
Hope you can help me out with this one..
nl2br($string) converts all the \n to <br \>
... but ..
Suppose I have a table or other HTML elements in $string..
All the TD> and TR> and FORM> are trailed by <br />
How can I adjust the function:
preg_replace("/\r\n|\r|\n/", "<br>\n", $r[body])
to ignore lines ending with >
(or: > n spaces )
Thanx in advance,
Marco Snoek 3 2819
On Thu, 11 Mar 2004 20:21:33 +0100, "Marco Snoek"
<_[mps]@[webmind.nl]_Dont_you_dare_ send.spam> wrote: Hope you can help me out with this one..
nl2br($strin g) converts all the \n to <br \>
.. but ..
Suppose I have a table or other HTML elements in $string.. All the TD> and TR> and FORM> are trailed by <br />
How can I adjust the function: preg_replace ("/\r\n|\r|\n/", "<br>\n", $r[body])
to ignore lines ending with > (or: > n spaces )
I think you're heading into trouble with this approach; what about the
following perfectly valid HTML:
<form method="get"
action="somethi ng.php"
name="whatever" >
You've now got a whole load of other exceptions to deal with.
The idea of nl2br is to convert _non-HTML_ text data containing newlines to an
HTML equivalent that has <br> elements so that it has newlines in the same
place when inserted into an HTML document.
In general, you can't parse HTML with a single regular expression, as regular
expressions aren't capable of maintaining states as necessary to implement a
HTML parser.
--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
You're absolutely right..
But....
I'm quite sure the trick should work.. I enter the input myself :-)
Can you think of a reg_exp ???
Regards...
Marco
"Andy Hassall" <an**@andyh.co. uk> schreef in bericht
news:8j******** *************** *********@4ax.c om... On Thu, 11 Mar 2004 20:21:33 +0100, "Marco Snoek" <_[mps]@[webmind.nl]_Dont_you_dare_ send.spam> wrote:
Hope you can help me out with this one..
nl2br($strin g) converts all the \n to <br \>
.. but ..
Suppose I have a table or other HTML elements in $string.. All the TD> and TR> and FORM> are trailed by <br />
How can I adjust the function: preg_replace ("/\r\n|\r|\n/", "<br>\n", $r[body])
to ignore lines ending with > (or: > n spaces ) I think you're heading into trouble with this approach; what about the following perfectly valid HTML:
<form method="get" action="somethi ng.php" name="whatever" >
You've now got a whole load of other exceptions to deal with.
The idea of nl2br is to convert _non-HTML_ text data containing newlines
to an HTML equivalent that has <br> elements so that it has newlines in the same place when inserted into an HTML document.
In general, you can't parse HTML with a single regular expression, as
regular expressions aren't capable of maintaining states as necessary to implement
a HTML parser.
-- Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
Marco Snoek wrote: Can you think of a reg_exp ???
You need the "lookbehind " stuff.
Open this URLi: http://www.php.net/manual/en/pcre.pattern.syntax.php
and search "lookbehind " in that page
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matthew Sims |
last post by:
Hey all,
So I started using nl2br and love it. But when I convert back from
<br> to \n, it produces double spaces instead of single space.
Converting \n to <br>:
$emailBody=nl2br($_POST);
$emailBody=str_replace("<br />", "<br>", "$emailBody");
Converting <br> to \n:
|
by: NotGiven |
last post by:
I have a form that inserts records in a database. When I display records,
the paragraphs don't show up.
I am using dreamweaver MX, PHP, and MySQL.
|
by: Jakanapes |
last post by:
Hi all,
I'm looking for a way to scan a block of text and replace all the
double quotes (") with single quotes (').
I'm using PHP to pull text out of a mySQL table and then feed the text
into a javascript function called by onClick. The problem is that the
text may contain single or double quotes, which screws up the
javascript. I eliminated the single quote problem by running the text
through addslashes, but the double quotes are a...
|
by: ribchr00 |
last post by:
Hi all,
I would like to replace line breaks such '+' with '<br />'. Easy
task. Problems start when I try to only replace lines that do not end
with HTML tags.
I tried preg_replace("/+/", "<br />\n") but this does not
seem to work.
An example to better understand what I would like to achieve:
first line
|
by: Chris Goldie |
last post by:
From an accessibility point of view, is there any advange in using <P>
over <br>?
eg, whats the difference between these two examples, are they both
accessible?
Eg. 1
<p>My first paragraph.</p>
<p>My second paragraph.</p>
| |
by: Turamnvia Suouriviaskimatta |
last post by:
I 'm following various posting in "comp.lang.ada, comp.lang.c++ ,
comp.realtime, comp.software-eng" groups regarding selection of a
programming language of C, C++ or Ada for safety critical real-time
applications. The majority of expert/people recommend Ada for safety
critical real-time applications. I've many years of experience in C/C++ (and
Delphi) but no Ada knowledge.
May I ask if it is too difficult to move from C/C++ to Ada?...
|
by: Wayne |
last post by:
$a = $_POST; # txt_content = This is a<CR><LF>Test
$p = str_replace ("%0D%0A", "<br>", $a);
That is the above code that I am using, however, it is not picking up
the CR/LF from the textarea. I have also attempted singular variations
of the CR/LF combination and even reversed the sequence without success.
Is it possible that it may be encoded differently and if so what is it?
Thanks
|
by: Ajm113 |
last post by:
Ok, I want to disable any html tags, but the problem is when I do add in the nl2br function with a htmlentities it displays the tags for the <br>! I even keep seeing rn every time I enter a return in that area from the textarea html command. So how do I have nl2br going and htmlentities going at the same time, but not having to disabling each other?
|
by: Defacta |
last post by:
Hello !
How to delete all the new lines and replace them by <br>, because new
lines involves Javacript Error, IE:
facts_infos = "In 1972 he was done for murdering a colleague
over a matter of $30! <br />
He served 2 years for this and was never seen again, blah blah blah."
What I do is:
|
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...
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |