<?php
function nowdoc_remove($match) {
	return "'" . strtr($match[2], array("'" => "\\'", "\\" => "\\\\")) . "'";
}

function nowdoc_glob($dir) {
	foreach (glob("$dir/*.php") as $filename) {
		$file = file_get_contents($filename);
		$file = preg_replace_callback("/<<<~[ \t]*(.*)\n(.*)\n\\1\\s*/sU", 'nowdoc_remove', $file);
		file_put_contents($filename, $file);
	}
	foreach (glob("$dir/*", GLOB_ONLYDIR) as $dir) {
		nowdoc_glob($dir);
	}
}

nowdoc_glob("phd");
