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) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -