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..
That is a wildcard character in a regular expression.
(<table.*?id=\"weekdays\".*)/./smeans ANY character*means 0 or more timesSo
/.*/smeans “match any character 0 or more times”STRING :
hello , now this is some garbage , world. And this is a long sentence which ends in worldhello.*worldwill match this WHOLE string.See example : http://regexr.com?334em
And
/.*?/smeans “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/swill match onlyhello , now this is some garbage , worldas it is the smallest non-greedy match.See same example with difference :
http://regexr.com?334ep
imsare flagsi,mandsYou can read about them here: PHP: Possible modifiers in regex patternsDocs