Skip to content

Instantly share code, notes, and snippets.

@nielsen
Created March 7, 2011 17:16
Show Gist options
  • Save nielsen/858818 to your computer and use it in GitHub Desktop.
Save nielsen/858818 to your computer and use it in GitHub Desktop.
Search and replace short open tags and short open echoes "<?=" recursively from project root.
require 'find'
Find.find(".") do |path|
if FileTest.directory?(path)
next
else
filename = File.basename(path)
if filename =~ /\.php/
s = IO.read(path)
compliant = s.gsub(/<\?\s/, "<?php ").gsub(/<\?=\s/, "<?php echo ")
File.open(path, 'w') {|f| f.write(compliant) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment