Last active
December 10, 2015 21:38
-
-
Save WA9ACE/4496200 to your computer and use it in GitHub Desktop.
Text Replacer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
content = '' | |
Dir.glob(['*.php', '*.html', '*.htm', '*.js', '*.css']).each_with_index do |filename, index| | |
file = File.read(filename) | |
# Ruby assumes all things created are UTF-8 which is false and will stop executing | |
# when if finds something that isn't. Hence this. | |
file.encode!('UTF-16', :undef => :replace, :invalid => :replace, :replace => "") | |
file.encode!('UTF-8') | |
file = file.gsub(/href="^http/, content) | |
File.open(filename, 'w') { |f| f.puts file } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment