Preg_Match help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
J0kerz
Forum Commoner
Posts: 37
Joined: Fri May 29, 2009 2:51 pm

Preg_Match help

Post 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
Last edited by J0kerz on Fri Jun 04, 2010 1:46 pm, edited 2 times in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Preg_Match help

Post by AbraCadaver »

Because you need preg_match_all() :)
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
J0kerz
Forum Commoner
Posts: 37
Joined: Fri May 29, 2009 2:51 pm

Re: Preg_Match help

Post by J0kerz »

Thanks for your fast reply Abracadaver!

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