Jump to content

Crazy Regexp


azuka

Recommended Posts

Hi,

I've been trying to write a regular expression that replaces newlines in text. For example,

[code]
Hullo there. This is an
example of something....

Paragraph break
[/code]

When the regexp encounters a double new line (a paragraph), it leaves it but changes the single ones to a space. Like the above would be changed to

[code]
Hullo there. This is an example of something....

Paragraph break.
[/code]

Can someone assist me?
Link to comment
https://forums.phpfreaks.com/topic/3997-crazy-regexp/
Share on other sites

[!--quoteo(post=351346:date=Mar 3 2006, 03:56 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 3 2006, 03:56 PM) [snapback]351346[/snapback][/div][div class=\'quotemain\'][!--quotec--]
what do you have so far? it may be easier just to see what you've tried and help you modify that to work
[/quote]

Thanks Gareth. I've fixed it. I had something someone typed up and I decided to use php to fix it because I couldn't use the regexp engine in Microsoft Word or OpenOffice.org. What I did looks like this.
[code]
$text = $_POST['txt'];
$text = str_replace("\r\n\r\n","^^^^",$text);
$text = str_replace("\r\n", " ",$text);
$text = str_replace("^^^^","\r\n\r\n",$text);
[/code]

It works perfectly now. Thanks for offering to help though.
Link to comment
https://forums.phpfreaks.com/topic/3997-crazy-regexp/#findComment-14475
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.