Page 1 of 1

Preg_Match help

Posted: Fri Jun 04, 2010 1:02 pm
by J0kerz
Hey there, I am habing trouble extracting information from an XML file using preg_match. It seems that the matches array cant go farther than offset 1 and I dont understand why..

Code: Select all


				$url = 'Removed';

				$user_agent='Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19';

				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_POST, 0);
				curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
				curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
				curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
				$source = curl_exec($ch);
				
	
				preg_match('-<Url>(.+)</Url>-', $source , $links);
				

				
					for ($z = 1; $z <= count($links) ; $z++){
					
					echo $links[$z].'<br>';
					

					}

					
					
					curl_close($ch);


Thanks alot!
:D

Re: Preg_Match help

Posted: Fri Jun 04, 2010 1:04 pm
by AbraCadaver
Because you need preg_match_all() :)

Re: Preg_Match help

Posted: Fri Jun 04, 2010 1:10 pm
by J0kerz
Thanks for your fast reply Abracadaver!

I corrected the problem reading: http://php.net/manual/en/function.preg-match-all.php