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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.