title: Batch script to replace PHP short open tags with <?php
body: <p>I have a large collection of php files written over the years and I need to properly replace all the short open tags into proper explicit open tags.</p>
  
  <pre><code>change "&lt;?" into "&lt;?php"
  </code></pre>
  
  <p>I think this regular expression will properly select them :</p>
  
  <pre><code>&lt;\?(\s|\n|\t|[^a-zA-Z])
  </code></pre>
  
  <p>which takes care of cases like</p>
  
  <pre><code>&lt;?//
  &lt;?/*
  </code></pre>
  
  <p>but I am not sure how to process a whole folder tree and detect the .php file extension and apply the regular expression and save the file after it has been changed.</p>
  
  <p>I have the feeling this can be pretty straightforward if you master the right tools. (There is an interesting hack in the sed manual: <a href="https://www.gnu.org/software/sed/manual/sed.html#Rename-files-to-lower-case" rel="noreferrer">4.3 Example/Rename files to lower case</a>).</p>
  
  <p>Maybe I'm wrong.<br>
  Or maybe this could be a oneliner?</p>