I want to get the js file by PHP CURL, then using regular express to get the value of var pluses, so the output should be /\+/g. Could someone advise what wrong with my code?
Thanks
Here is what I have tried, but no luck:
$url = 'http://cdn.jsdelivr.net/jquery.cookie/1.3/jquery.cookie.js';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
preg_match('/^var\spluses\s=\s/', $output, $match);
print_r($match);
Live code: http://phpfiddle.org/main/code/x4w-cn5
To get your match, you need to select it. try
The value assigned to pluses should be in
$match[1].The
^at the beginning of your regex is the start of line delimiter, which limited the selection to a line starting with the charactersvar, not considering the indentation.This regex would limit to a line with any (
*) whitespaces before thevarkeyword.