Jump to content

breaking a text file into paragraphs based on strings


myscripting

Recommended Posts

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

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.

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.