Created
April 23, 2022 19:12
-
-
Save k3a/6bc61f9d71acc8fecc4a3c23cdb36e9e to your computer and use it in GitHub Desktop.
A tiny Ruby tool to change <? to <?php in each file inside a specified directory including sub-directories
This file contains hidden or 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
Raw | |
Blame | |
#!/usr/bin/env ruby | |
# PHP file tag fixer by K3A.me | |
# Changes <? to <?php in each file | |
abort("Usage: fixphp.rb <path_to_a_folder>") if ARGV.length == 0 | |
Dir[ARGV[0]+"/**/*"].each do |fn| | |
next if File.directory?(fn) | |
puts " * #{fn}" | |
begin | |
data = File.read(fn).gsub(/<\?([^p])/, '<?php \1') | |
File.open(fn, 'w') { |f| f << data } | |
rescue | |
$stderr.puts " #{$!}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment