Jump to content

[SOLVED] delete (or replace with "") a line in a text file if has exactly two '\" c


solarisuser

Recommended Posts

Hi All,

 

I have a text file that contains directory paths.  My goal is to delete the line from the text file if it has exactly two "\" characters, no more and no less.

I've thought about using count_chars() but I can't figure out the best way to integrate it with preg_match_replace or something of the like.

 

Any help would be much appriciated! 

Thanks

I don't have(or know) the exact code, but it should be something like this:

 

-read file A line by line

-write each line to file B, as long as it's not blank(or long as it's not whatever line you want to not be printed), so you'd do a conditional[ if($data != "whatever") fprintf(something); ] or something to that effect. Look up fopen, fprintf, and similar functions, then you'll gert an idea of how to write the code for it.

 

 

that's pretty much it.

thanks but i got that part down no problem.

 

the thing is, while im reading each line of text i need to use some regex to find out if that line has two occurances of "\" and delete that line, then continue...

I need to use regex because the data is dynamically generated

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.