1

i am getting a page with php function like following

<?php $html = file_get_contents('http://www.domain.com');?>

i want to get anchor tag name field value using php. that is like

<a href="something" name="something">some value</a>

I don't know how to do it. found nothing in google it.

saad
  • 581
  • 1
  • 6
  • 11
  • 2
    Looks like you didn't look hard enough in Google, then: http://www.php.net/manual/en/book.dom.php – BenM Mar 27 '14 at 15:47
  • @BenM is right. And if you need smth. specific, you can use regular expression too. – lvil Mar 27 '14 at 15:48
  • @BenM I've struck my head against this link already but couldn't understand it at all seriously. – saad Mar 27 '14 at 15:58
  • Then it sounds like you either need to study the docs more closely, or hire a web developer. Seriously, no-one's going to spoon-feed it to you here. Sorry. – BenM Mar 27 '14 at 16:01
  • Did you get your question answered? (If so, accept one?) – dcromley Apr 24 '14 at 16:55

1 Answers1

0

This should get you going if you need to use PHP. But maybe you want to work in JS in the client? The code is commented. Obviously you need to get to BenM's link.
z1.htm:

<html><head></head><body>
<a href="something" name="something">some value</a>
<a href="something2" name="something2">some value2</a>
<a href="something3" name="something3">some value3</a>
</body></html>

z1.php:

<?php
$sfile = file_get_contents('z1.htm'); // loads file to string
$html = new DOMDocument; // is object class DOMDocument
$html->loadHTML($sfile); // loads html
$nodelist = $html->getElementsByTagName('a'); // nodes
foreach ($nodelist as $node) {
  echo $node->nodeValue, "<br />\n"; }
?>
dcromley
  • 1,373
  • 1
  • 8
  • 23