Reputation: 5283
i just wanna ask what this symbol .*? means in php. here is the sample code:
function parse($html) {
//echo "Find table(id=weekdays)..\n";
$pattern = "/(<table.*?id=\"weekdays\".*)/ims";
//$pattern = "/(<div.*?id=\"flexBox_flex_calendar_mainCal\".*)/ims";
//echo $pattern."\n";
$match = array();
//$html = str_replace("\r", "", $html);
//$html = str_replace("\n", "", $html);
if (preg_match($pattern, $html, $match) > 0) {
//print_r($match);
//echo $match[1];
//echo count($match);
$this->parseTable($match[1]);
} else {
echo "Error: no match calendar data(table id=weekdays) found, maybe fx.com change its site html'!\n";
}
}
I am maintaining a website that has the function to extract the table values from another/an external website then parse it to insert on our database..
I have to change the value of $pattern but i cant since i didn't know what does that symbols mean..
Thank you so much for the help..
Upvotes: 1
Views: 481
Reputation: 631
http://weblogtoolscollection.com/regex/regex.php
http://webcheatsheet.com/php/regular_expressions.php
these may be helpful for you
Upvotes: 1
Reputation: 43245
That is a wildcard character in a regular expression.
(<table.*?id=\"weekdays\".*)
/./s
means ANY character
*
means 0 or more times
So /.*/s
means "match any character 0 or more times"
STRING : hello , now this is some garbage , world. And this is a long sentence which ends in world
hello.*world
will match this WHOLE string.
See example : http://regexr.com?334em
And /.*?/s
means "match any character 0 or more times, but the non greedy match i.e. The earliest match is returned (here: a zero-length string).
/hello.*?world/s
will match only hello , now this is some garbage , world
as it is the smallest non-greedy match.
See same example with difference : http://regexr.com?334ep
ims
are flags i
, m
and s
You can read about them here: PHP: Possible modifiers in regex patternsDocs
Upvotes: 3
Reputation: 94121
That is called a regular expression, you can learn more here: http://www.regular-expressions.info/
/.*?/ims
means "match any character, if any ( non-greedy )".
Upvotes: 4