The problem of regular expression matching url address for help I want to match the http://www.so.com/s? Q = csdn & pn = 7 & j = the url of each search result in 0. the result of matching with the following regular expression is null. where is the error?
$c1 = "/\s*(?:.*)<\/a>\s*<\/h3>/Uis";$content= get_content('http://www.so.com/s?q=csdn&pn=7&j=0');preg_match_all($c1,$content,$arr1);print_r($arr1);
Reply to discussion (solution)
You should reconsider the method of asking questions. in this way, few people are willing to answer questions.
The full text cannot be found.
I used DOM parsing, and the regular expression was unfamiliar. the href was too long. I used preg_match_all twice and barely matched it.
$urls = 'http://www.so.com/s?q=csdn&pn=7&j=0';$ch = curl_init();curl_setopt($ch, CURLOPT_URL,$urls);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$content = curl_exec($ch);curl_close($ch);$c1 = "/
(.*?)(.*?)<\/a>(.*?)<\/li>/is";preg_match_all($c1,$content,$arr1);foreach($arr1[0] as $part){$c2 = "/href=('|\")(.*?)(?1)\s+/is";preg_match_all($c2,$part,$arr2);echo $arr2[2][0].'
';}