Monday, March 6, 2017

Replace php short tags in all php files with netbeans

I've needed to replace short php tags (<?) in my old php files to standart php tags (<?php) for compatibility on most servers. I've found a regular expression which you can use in netbeans or another IDE/editor to make this change quickly in all your project files. To apply replace first open your netbeans project and click the project name on side menu as a selection of scope. You can select a subfolder too if you want to apply replace limited to scripts in a directory. Then type Ctrl + H to open replace tool window. Enter Containing Text and Replace With values as following:

Containing Text: <\?( )*(?!php)(?!=)(?!xml)(?!mso)
Replace With: <?php

Note that the replace text should contain a space at the end to avoid problems. Also make sure match option is selected as Regular Expression. You can enter File Name Patterns value as *.php if you need.




When ready click Continue to let netbeans find all replaces. If it finds any you should see the results like that:




You can select which results will be replaced by using the checkbox for each file. When ready click the replace button at the bottom to replace php short tags in files.

By applying this replace on netbeans or another IDE which has this feature, you can update short tags to standart php tags which is a better usage. However the usage of <?= ?> style expressions don't need to be replaced as you may have noticed in the regular expression rule we've used.

No comments:

Post a Comment