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? Link to comment https://forums.phpfreaks.com/topic/3997-crazy-regexp/ 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 Link to comment https://forums.phpfreaks.com/topic/3997-crazy-regexp/#findComment-13921 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. Link to comment https://forums.phpfreaks.com/topic/3997-crazy-regexp/#findComment-14475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.