Jump to content

Preg_Match Help


twittoris

Recommended Posts

I have a DOMDocument which I inspect an HTML page for links (href)

That part works however I am not sure how to use preg_match if I only want to display a link in this layout:

 

<tr>

<td headers="c1"><a title="Link to entity information." tabindex="1" href="CORPSEARCH.ENTITY_INFORMATION?p_nameid=3236937&p_corpid=3227476&p_entity_name=%41%72%77%65%6E%20%45%71%75%69%74%69%65%73&p_name_type=%41&p_search_type=%42%45%47%49%4E%53&p_srch_results_page=0">ABC LLC</a></td>

 

</tr>

 

 

I hope someone is really good at preg_match to help me. Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/212532-preg_match-help/
Share on other sites

I am fairly new at this so I have inserted my code.

this is making it say Array over and over again in my database.

 

 

// parse the html into a DOMDocument

$dom = new DOMDocument();

@$dom->loadHTML($html);

 

// grab all the on the page

$xpath = new DOMXPath($dom);

$hrefs = $xpath->evaluate("/html/body//a");

 

 

for ($i = 0; $i < $hrefs->length; $i++) {

$href = $hrefs->item($i);

$url = $href->getAttribute('href');

$patern ='/href="([^"]*)"/';

preg_match_all($patern, $text, $out);

print_r($out[300]);

$sql="INSERT INTO links(cid, nlink)VALUES('$out()','$out')";

$result=mysql_query($sql);

Link to comment
https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107257
Share on other sites

i see in another your post thet you want href wich start with 'CORPSEARCH.ENTITY_INFORMATION?'

in that case use

$patern ='/href="(CORPSEARCH\.ENTITY_INFORMATION\?[^"]*)"/';
preg_match_all($patern, $text, $html);
$url =$out[1][0]; 
$sql="INSERT INTO links(cid, nlink)VALUES('','$url')";

Link to comment
https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107260
Share on other sites

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.