Forum Moderators: coopster
$pattern = "/<script[^>]*>(.*)<\/script>/Uis";
preg_match_all($pattern, $string, $matches);
print_r($matches);
$content = file_get_contents($uri);
$pattern = "/<script[^>]*>(.*)<\/script>$/Uis";
preg_match_all($pattern, $content, $matches);
print_r($matches);
I expect output cotaining all the javascript constructs used used in the Web page. Not anything other than this.
$content = htmlentities($content);
$pattern = "/(<script)(.*)(<\/script>)/i";
preg_match_all($pattern, $content, $matches);
while( list($key, $value) = each($matches[0]) )
echo "<br>" . $value . "<br>";
I checked for few URIs, it done well. Though not sure! I'm trying more URIs ..
Can some one tell me, why results of preg_match_all() is in 2-dimensional array. I noted all the times, $matches[0] is only useful. Why other ones are vague?
In emample above, I couldn't undertand U and ^ modifiers!
If $ is a match at end-modifier, why putting $pattern = "/(<script)(.*)(<\/script>$)/i"; in this code, makes the result array null?
Please explain.
I'm a regex novice. I've one last question: Is using lenghty regex slows the script. I mean, is there some efficieny concern, while using regexs or PHP Perl-compatible regex functions?
Thanks.
$pattern = "/<script.*javascript[^>]*>(.*)<\/script>/Uis";
The '$' anchor means the last character or last part of the subject string. Very last, not just "the last part of my particular pattern".
But my problem is solved and I've uploaded the js tool live! First, I used htmlentities()
and then this pattern: $pattern = "/(<script)[a-z0-9¦>,;#!\"'()%~:_=&\-\.\?\/\s]*(<\/script>)/Ui";
U is critical in above.
Thanks for motivation ;)