Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2004, 06:03 PM   PM User | #1
me'
Senior Coder

 
Join Date: Nov 2002
Location: Warwickshire, England
Posts: 1,229
Thanks: 0
Thanked 0 Times in 0 Posts
me' is an unknown quantity at this point
Matching double line breaks

I'm trying to double line breaks in a user-entered field into XML. I've tried matching them with a simple regexp:
Code:
'<paragraph>' . preg_replace('/^^/m', "</paragraph>\n\n<paragraph>", $_POST['post']); . '</paragraph>'
This does seem to be matching the paragraphs, but it goes over the top. For example,
Quote:
hello

world
Gives
Code:
<paragraph></paragraph>

<paragraph>hello

</paragraph>

<paragraph>

</paragraph>

<paragraph>world</paragraph>
Any insight/solutions?
__________________
David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!
me' is offline   Reply With Quote
Old 01-22-2004, 06:58 PM   PM User | #2
me'
Senior Coder

 
Join Date: Nov 2002
Location: Warwickshire, England
Posts: 1,229
Thanks: 0
Thanked 0 Times in 0 Posts
me' is an unknown quantity at this point
All right, no-one seems to have a clue. Perhaps relevant: I'm using Windows which uses [lf][cr] to mark new lines, compared to unix where simply [lf] is used. Could this be why?
__________________
David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!
me' is offline   Reply With Quote
Old 01-23-2004, 02:07 PM   PM User | #3
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
thats exactly the reason

run an str replace to delete all occurances of \r

as for matching double line breaks why not use "'\n\n's" ? ( i use a single quote as a delimiter)
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline   Reply With Quote
Old 01-23-2004, 05:48 PM   PM User | #4
me'
Senior Coder

 
Join Date: Nov 2002
Location: Warwickshire, England
Posts: 1,229
Thanks: 0
Thanked 0 Times in 0 Posts
me' is an unknown quantity at this point
Finally got it to work! Thanks! Here's my final code:
Code:
  $postnew = str_replace("\r", '', $_POST['post']);
  $postnew = str_replace("\n\n", "[ot]/paragraph[ct]\n\n[ot]paragraph[ct]", $postnew);
__________________
David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!
me' is offline   Reply With Quote
Old 01-23-2004, 05:51 PM   PM User | #5
bcarl314
Mega-ultimate member


 
Join Date: Jun 2002
Location: Winona, MN - The land of 10,000 lakes
Posts: 1,855
Thanks: 1
Thanked 45 Times in 42 Posts
bcarl314 will become famous soon enough
Just a comment,

Thanks for posting your solution. All to often I notice people get things to work and simply post something like "I got it, thanks". Although this is great, It really annoys me when I search this forum and can't find the answer because it wasn't added at the end of the thread.

I know I too am guilty, but I just wanted to point it out and say thanks me'
bcarl314 is offline   Reply With Quote
Old 01-23-2004, 09:52 PM   PM User | #6
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
am i correct to assume that you later change all occurances of [ot] and [ct] into < and > respectively?
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline   Reply With Quote
Old 01-23-2004, 10:06 PM   PM User | #7
me'
Senior Coder

 
Join Date: Nov 2002
Location: Warwickshire, England
Posts: 1,229
Thanks: 0
Thanked 0 Times in 0 Posts
me' is an unknown quantity at this point
Quote:
Originally posted by bcarl314
I know I too am guilty, but I just wanted to point it out and say thanks me'
No problem
Quote:
am i correct to assume that you later change all occurances of [ot] and [ct] into < and > respectively?
Yep, I was passing a string with < and > into an XSLT file, and getting well formed errors, so I swapped out < and > with [ot] and [ct], and use another str_replace later on.
__________________
David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!
me' is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:12 AM.


Advertisement
Log in to turn off these ads.