regex - What is differerent between using $subject and substr($subject,3) in example preg_match() in php.net -
regex - What is differerent between using $subject and substr($subject,3) in example preg_match() in php.net -
i read how utilize function preg_match in http://php.net/manual/en/function.preg-match.php, don't know differerent between using $subject , substr($subject,3) in preg_match($pattern, $subject, $matches, preg_offset_capture, 3) , preg_match($pattern, substr($subject,3), $matches, preg_offset_capture). please help me understand , check below function why homecoming empty array?
<?php $ch=curl_init(); curl_setopt($ch,curlopt_url,"http://www.1gom.us/ti-le-keo-malaysia.html"); curl_setopt($ch,curlopt_returntransfer,true); $content = curl_exec($ch); curl_close($ch); $regex = '/<div class="tabbox" id="tabbox">(.*)<\/div>/'; preg_match($regex, $content, $matches, preg_offset_capture, 3); $table = $matches[1]; print_r($table); ?>
you obtain same result. if utilize substr, create new string nothing, when lastly parameter of preg_match inquire begin search @ particular offset of subject string.
the reason obtain empty result due fact .
can't match newlines default. can alter behavior s
modifier:
$regex = '~<div class="tabbox" id="tabbox">(.*?)</div>~s';
(note utilize of different modifier not have escape slashes. note utilize of non-greedy quantifier stop @ first occurence of </div>
)
however, noticed in comments, extracting informations html document more easy combo domdocument/domxpath (depending of how looks document , trying do).
php regex
Comments
Post a Comment