Skip to content

Instantly share code, notes, and snippets.

@k3a
Created April 23, 2022 19:12
Show Gist options
  • Save k3a/6bc61f9d71acc8fecc4a3c23cdb36e9e to your computer and use it in GitHub Desktop.
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
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