Replacing PHP short tags with powershell

      2 Comments on Replacing PHP short tags with powershell

This code-snippet should allow you to quickly replace PHP short tags with regular PHP open tags:

(Get-Content C:\Scripts\test.php) | 
Foreach-Object {$_ -replace "<\?", "
							

2 thoughts on “Replacing PHP short tags with powershell

  1. Ixium

    Hi WiZZarD,

    Your code-snipper contains a weakness. When you have xml-code in a php-script, the <?xml – tags will also be replaced by <?php – tags

    It's better to place a white-space after "<\?

    Best Regards,
    Ixium ;)

    1. WiZZarD Post author

      Partially true. This will mall-form valid xml files indeed. But: your fix will only work if people have used an extra space after their opening tag. If the space isn’t there, or is a newline/linefeed character, it won’t match and therefore won’t replace the text.

      A possible fix for this would be to match either

Comments are closed.