preg_match_all <script></script> match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$html = <<<HTML | |
<html> | |
<head> | |
<script src="http://example.com"></script> | |
</head> | |
<body> | |
<div> | |
<script> | |
// inline js | |
$(document).ready( function() { | |
}); | |
</script> | |
Hello World | |
</div> | |
</body> | |
</html> | |
HTML; | |
$regex = "/\<script(.*?)?\>(.|\\n)*?\<\/script\>/i"; | |
preg_match_all($regex, $html, $scripts); | |
print_r($scripts); | |
/* ** | |
Need regex such that print_r($scripts) will give me: | |
array( | |
[0] => <script src="http://example.com"></script> | |
[1] => <script>// inline js$(document).ready( function() {});</script> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment