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
Share on other sites

href="          - literaly

(                  - start groupin

[^"]*          - any caracter diferant that " zero or more time

)                  - end gruping

"                - end caracter

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.