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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -