I have to match local src's and make them load via the web. Example:
src="/js/my.js">
Becomes:
src="http://cdn.example.com/js/my.js">
This is what I have now:
if (!preg_match("#<script(.+?) src=\"http#i",$page)){
$page = preg_replace("#<script(.+?) src=\"#is", "<script$1 src=\"$workingUrl", $page);
}
It works fine when it encounters something like this:
<script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script>
It fails when it encounters something like this:
<script language="JavaScript">
window.moveTo(0,0);
window.resizeTo(screen.width,screen.height);
</script>
If the script tag doesn't contain a src it will then find the src of the first image tag and switch out its URL.
I need to know how to get it to terminate the match on the script tag only and/or how to perform the replacement better.