kevinkhan
10-26-2009, 04:17 PM
I came across this line in a code that i have and i dont know what it means
$strContent = file_get_contents($strListingUrl);
$strListMatches = '!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU';
$objListMatches = getMatches($strListMatches,$strContent);
can anyone explain it in simple english for me please
oracleguy
10-26-2009, 04:25 PM
That string is a regular expression. The .* means match any character 0 or more times.
kevinkhan
10-26-2009, 04:41 PM
so does this code mean that it gets everything in a page and sets it as a variable $strContent and then takes everything out that matches
'!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU'
and puts them into $objListMatches
Yes?
is $objListMatches now an array?????
Thanks for your help
Lamped
10-26-2009, 04:45 PM
I came across this line in a code that i have and i dont know what it means
$strContent = file_get_contents($strListingUrl);
$strListMatches = '!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU';
$objListMatches = getMatches($strListMatches,$strContent);
can anyone explain it in simple english for me please
Yeah, what oracleguy said, except... It doesn't work...
$strListMatches = '!<a class="details" href="(.*?)" title="(.*?)">(.*?)</a>!isU';
Or...
$strListMatches = '!<a class="details" href="([^"]*)" title="([^"]*)">(.*?)</a>!isU';
Why doesn't it work, I hear you cry?!
<a class="details" href="a" title="b">c</a><a class="details" href="d" title="e">f</a>
Will match the first:
href="a"
as
href="a" title="b">c</a><a class="details" href="d
Because .* also matches the closing "
oracleguy
10-26-2009, 05:07 PM
so does this code mean that it gets everything in a page and sets it as a variable $strContent and then takes everything out that matches
'!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU'
and puts them into $objListMatches
Yes?
is $objListMatches now an array?????
Thanks for your help
getMatches isn't a standard PHP function, it must be a user created one so I can't say what it is doing without seeing the implementation.
Yeah, what oracleguy said, except... It doesn't work...
$strListMatches = '!<a class="details" href="(.*?)" title="(.*?)">(.*?)</a>!isU';
Or...
$strListMatches = '!<a class="details" href="([^"]*)" title="([^"]*)">(.*?)</a>!isU';
Why doesn't it work, I hear you cry?!
<a class="details" href="a" title="b">c</a><a class="details" href="d" title="e">f</a>
Will match the first:
href="a"
as
href="a" title="b">c</a><a class="details" href="d
Because .* also matches the closing "
Yep you're right; using the period character like that is a common mistake made by people inexperienced with regular expressions.
chyssa
10-27-2009, 03:21 AM
Thanks for sharing your codes...