Forum Moderators: open
I use Notepad++, which kind of does this with the "Find" and "Replace All" functions, but this only works with a small number of characters. I want to basically replace a block of code with another block of code... or just add a block of code to a specific spot without replacing anything.
Does anyone know if there is any way to do this or any program that will give me this capability?
Thanks in advance for any help.
//use scandir to get all files, PHP 5+
foreach(scandir($mydiroffiles) as $value){
//dont look at .. and . in directory, linux and windows
if($value !== "." && $value !== ".."){
//create handle for opening file for writing
$handle = fopen($value,"w");
//get content of file into string
$fileContent = fread($handle,filesize($value));
//replace using regular expression
$fileContent = preg_replace($regex,$replacewith,$fileContent);
//write new contents to file
fwrite($value,$fileContent);
//close handle
fclose($handle);
}
//cycle back through for each file
}
good luck
Another, nonobvious, candidate is Microsoft Visual C++ Express (free). It's a programming environment, but its search and replace (including regex and multi-file searching) is very good.
[edited by: SteveWh at 3:18 am (utc) on Dec. 25, 2008]
In my search of PHP IDE, I have come across Eclipse for PHP. This has a file find and replace, by exact phrase or regex. In addition you can choose what folders for it to search.
In addition, it is simply the best editor/programming tool I have used thus far. Did I mention it is FREE!
comes with code hints, SVN, pluggin for any programming language. The best search function. I have been only using if for about a month now. Just been unwilling to pay zen, phpIDE, etc...
I recommend everyone try it. Not a WYSIWYG though.
And still, hands down, the best HTML code editing software ever.
Mass search and replace:
All open files (organized in tabs, years before tabs were cool).
All files in a directory.
All files in a group of directories.
For old "code junkies" who never cottoned on to WYSIWIG design tools that generate their own (bloated) code, it still reigns supreme. (IMHO)
Failing that, learn Bash Scripting [tldp.org]. Specifically how to use grep [ss64.com] to pull and swap text between files.
Teaching yourself Bash might seem excessive for one little project, but it's time well spent in the long run if you ever plan on running your own servers.
Let's say you have a wish to add a class="green" on all <a> tags that are inside a <p> that has an attribute class="widget", but no id.
Good luck to do it if you can't parse the tree semantically.
And yes, SSI or PHP includes are the way to go for as many page elements as possible other than the main content.
swa66, that sounds incredibly cool. Assuming well-structured xhtml, what would you use to do the kind of editing you're talking about?
EditPadPlus works great for find-replace stuff. It also has handy features like "Open Folder" and "Save All" that make it great for handling large numbers of files at once. Very fast and light too.
BBedit (Mac) has wild card features, allowing you to search and replace text even if it has some different characters, you can use # for numbers, you can use * and such.