Graxeon Posted November 30, 2009 Share Posted November 30, 2009 I have this file and I want to remove the first few characters of it: $file001 = array("http://site.com/file.php?url=001"); $file002 = array("http://site.com/file.php?url=002"); $file003 = array("http://site.com/file.php?url=003"); $file004 = array("http://site.com/file.php?url=004"); $file005 = array("http://site.com/file.php?url=005"); $file006 = array("http://site.com/file.php?url=006"); $file007 = array("http://site.com/file.php?url=007"); $file008 = array("http://site.com/file.php?url=008"); $file009 = array("http://site.com/file.php?url=009"); $file0010 = array("http://site.com/file.php?url=0010"); $file0011 = array("http://site.com/file.php?url=0011"); $file0012 = array("http://site.com/file.php?url=0012"); $file0013 = array("http://site.com/file.php?url=0013"); $file0014 = array("http://site.com/file.php?url=0014"); $file0015 = array("http://site.com/file.php?url=0015"); $file0016 = array("http://site.com/file.php?url=0016"); $file0017 = array("http://site.com/file.php?url=0017"); $file0018 = array("http://site.com/file.php?url=0018"); $file0019 = array("http://site.com/file.php?url=0019"); $file0020 = array("http://site.com/file.php?url=0020"); $file0021 = array("http://site.com/file.php?url=0021"); $file0022 = array("http://site.com/file.php?url=0022"); $file0023 = array("http://site.com/file.php?url=0023"); $file0024 = array("http://site.com/file.php?url=0024"); $file0025 = array("http://site.com/file.php?url=0025"); So in the end I just want this left: "http://site.com/file.php?url=001"); "http://site.com/file.php?url=002"); "http://site.com/file.php?url=003"); "http://site.com/file.php?url=004"); etc I know Notepad++ has a "Replace" feature but it doesn't remove all of the changing numbers next to "$file" Is there a PHP code or a tool that does this? Quote Link to comment https://forums.phpfreaks.com/topic/183363-remove-__-amount-of-characters/ Share on other sites More sharing options...
mikesta707 Posted November 30, 2009 Share Posted November 30, 2009 Notepad++ has a regex search mode you could probably use Quote Link to comment https://forums.phpfreaks.com/topic/183363-remove-__-amount-of-characters/#findComment-967858 Share on other sites More sharing options...
Alex Posted November 30, 2009 Share Posted November 30, 2009 Notepad++ actually supports Regular Expressions. If you press Ctrl + F then goto the replace tab you can check the box that says "Regular Expressions". Then search for: $[^"]* and replace it with nothing you'll be left with what you want. Quote Link to comment https://forums.phpfreaks.com/topic/183363-remove-__-amount-of-characters/#findComment-967859 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 untested phpcode $contents = file_get_contents("file.txt"); $result = preg_replace('%^.*?("http://site\.com/file\.php\?url=\d+"\);$)%i', '\1', $contents); file_put_contents($result,"file2.txt"); Quote Link to comment https://forums.phpfreaks.com/topic/183363-remove-__-amount-of-characters/#findComment-967861 Share on other sites More sharing options...
Graxeon Posted November 30, 2009 Author Share Posted November 30, 2009 Wow...that works . So can you explain the "$[^"]*" search method in Notepad++ for me please? I'm not clear on how that functions. Quote Link to comment https://forums.phpfreaks.com/topic/183363-remove-__-amount-of-characters/#findComment-967877 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 everything that's not a " with nothing ie $file001 = array(" <--until that quote Quote Link to comment https://forums.phpfreaks.com/topic/183363-remove-__-amount-of-characters/#findComment-967882 Share on other sites More sharing options...
Graxeon Posted November 30, 2009 Author Share Posted November 30, 2009 Ok, thank you very much. I've learned many things today Quote Link to comment https://forums.phpfreaks.com/topic/183363-remove-__-amount-of-characters/#findComment-967885 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.