Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.