azuka Posted March 3, 2006 Share Posted March 3, 2006 Hi,I've been trying to write a regular expression that replaces newlines in text. For example,[code]Hullo there. This is anexample 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? Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 3, 2006 Share Posted March 3, 2006 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 Link to comment Share on other sites More sharing options...
azuka Posted March 5, 2006 Author Share Posted March 5, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.