myscripting Posted October 19, 2009 Share Posted October 19, 2009 I have a text file of email addresses that is all squished together. It looks like this: [email protected]@[email protected]@mail.net... What I want to do is insert a paragraph after every instance of "com" or "net" etc so I can read it as a list like this: [email protected] [email protected] [email protected] [email protected] thanks Link to comment https://forums.phpfreaks.com/topic/178166-breaking-a-text-file-into-paragraphs-based-on-strings/ Share on other sites More sharing options...
cags Posted October 19, 2009 Share Posted October 19, 2009 Simplest option would be str_replace. Something like... $ext = array('.com', '.net'); $ext_replace = array(".com\r\n", ".net\r\n"); str_replace($ext, $ext_replace, $input); Since . is a valid character in e-mail addresses you could get some false positives as [email protected] has .com in the middle of it. You could possibly cut down on these with a regular expression, but due to the nature of the string I'm not sure how you'd do that. Link to comment https://forums.phpfreaks.com/topic/178166-breaking-a-text-file-into-paragraphs-based-on-strings/#findComment-939588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.