php - Create a pattern to replace all script sources -
how can create pattern replaces scripts sources in php document string?
for example have $haystack = '<script src="oldscript.js"></script>';
and should $haystack = preg_replace('/src="[a-za-z0-9]{1,250}"/', 'myscript.js', $haystack);
but not work. doing wrong ? or there way this?
you need include dot in regex , add src="..."
in replacement:
$haystack = preg_replace('/src="[\w.]{1,250}"/', 'src="myscript.js"', $haystack);
Comments
Post a Comment