A small Python script that rewrites PHP include() / include_once() / require() / require_once() calls into the parentheses-free form.
Example:
include('config.php');
require_once("init.php");becomes:
include 'config.php';
require_once "init.php";To avoid breaking code, the script only rewrites a line when:
- The line contains exactly one
include(...)/require(...)statement, and - Everything else on that line is only whitespace and/or PHP comments (
//,#,/* ... */)
If the same line contains any other code (besides comments/whitespace), it is left unchanged.
Notes:
- The script detects comments outside of string literals.
- Multi-line block comments
/* ... */are handled correctly across lines.
- Python 3.8+ (works with Python 3.14 as well)
Run from the repository root:
python3 replace-php-includes.pyThe script will recursively process all *.php files in the current directory and subdirectories.
python3 replace-php-includes.py --dry-runBy default, the script creates a backup next to each modified file:
file.php→file.php.bak
Backups are created only for files that actually changed, and only if the .bak file does not already exist.
Disable backups:
python3 replace-php-includes.py --no-backup- Run a dry run:
python3 replace-php-includes.py --dry-run
- Run the rewrite:
python3 replace-php-includes.py
- Review changes using your VCS (recommended):
git diff
(c) 2026, vibecoded by utilmind
MIT