solarisuser Posted July 17, 2008 Share Posted July 17, 2008 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 Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 17, 2008 Share Posted July 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
solarisuser Posted July 17, 2008 Author Share Posted July 17, 2008 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 Quote Link to comment Share on other sites More sharing options...
corbin Posted July 18, 2008 Share Posted July 18, 2008 /^[\\]{1}[^\\]*?[\\]{1}[^\\]$*/ or just if(substr_count($str, "\\") == 2) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.