0

Due to the nature of Drupal Calendar's confusing web of functions I'm going to have to do something different.

I need to grab the id tag and its value from an array containing html code.

<div class="view-item view-item-calendar" id="node-154">
  <div class="calendar.111.field_showtimes_two.0.0 calendar monthview mainstagetheatre-highlight">
              <div class="view-field view-data-node-title node-title">


        <a href="/tca/mainstage/ninetofivemusical">9 to 5: The Musical</a>      </div>  
      </div>    
</div>

This is the code I will need to parse. Is it possible to target that id tag and whatever I set it as? Im doing it this way because I don't know where the array is created so I can add a node id, so I have to add it where the html is created.

Adam
  • 8,849
  • 16
  • 67
  • 131
  • Do you have to use php to do this, or can javascript do it? Is there going to be only one id attribute in the blob you are inspecting, or could there be multiple. If multiple, which do you want? – Explosion Pills May 04 '11 at 04:34
  • there will be only one node-id. yes it has to be php, because Drupal has a convoluted web of dynamically added .js,.css I would rather not add to the clutter. – Adam May 04 '11 at 04:42

2 Answers2

0

You need an HTML parser. Don't try to do it using regular expression.

To choose an HTML parser refer to this topic Robust and Mature HTML Parser for PHP

Community
  • 1
  • 1
ariel
  • 15,620
  • 12
  • 61
  • 73
0

ariel is right. Use an (X)HTML parser. This should work:

$dom = new DOMDocument;
$dom->loadHTML($html_from_above);
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//@id') as $node) {
   echo $node->value //found!
}

Alternatively, since you have only one single id, you might just want to use regex anyway. Better yet, use strpos/substr.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405