Jump to content

Need help with preg match


jbradley04

Recommended Posts

Hello,

I am trying to crawl a website and get all the domain names listed on the site to output into my php script. 

I am using the following code.... 

The main area is the preg match area, since I know nothing about it, nor do I understand it a little bit!

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://link I am getting data from.com);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
// Search The Results From The Starting Site
if( $result )
{
// LOOKING FOR ANYTHING.COM  all .com's
preg_match_all( "(.*)\.com", $result, $output, PREG_SET_ORDER );

foreach( $output as $item )

{
// ALL LINKS DISPLAY HERE 
print_r($item);



}

}

 

Any help would be greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/261216-need-help-with-preg-match/
Share on other sites

Just as Teynon said, need a delimiter,  http://php.net/manual/en/regexp.reference.delimiters.php

 

preg_match_all( "/(.*)\.com/", $result, $output, PREG_SET_ORDER );
preg_match_all( "@(.*)\.com@", $result, $output, PREG_SET_ORDER );
preg_match_all( "~(.*)\.com~", $result, $output, PREG_SET_ORDER );

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.