-1

Possible Duplicate:
Best way to parse HTML with PHP

I'm new to PHP and want to extract the second date from a string of this format :

<span class="date-display-start">28.12.2011</span><span class="date-display-separator"> - </span><span class="date-display-end">05.01.2012</span>

I'm not sure what PHP functions I can best use to do this ?

Community
  • 1
  • 1
Dave Shaw
  • 649
  • 1
  • 5
  • 3

2 Answers2

2

I'd use a simple regular expression. Using the DOMXPath class or similar seems overkill, assuming you don't need more advanced data extraction than this.

preg_match('/<span class="date-display-end">(.*)<\/span>/U', $str, $result);
print array_pop($result);
kba
  • 19,333
  • 5
  • 62
  • 89
0

You can get this in many different ways, the one of which is "/\d{2}\.\d{2}\.\d{4}/" regular expression:

<?php

$subject = '<span class="date-display-start">28.12.2011</span><span class="date-display-separator"> - </span><span class="date-display-end">05.01.2012</span>';

$regexp = '/\d{2}\.\d{2}\.\d{4}/';

preg_match_all($regexp, $subject, $matches);

print $matches[0][1];

The code above will print "05.01.2012", as in this demo.

Tadeck
  • 132,510
  • 28
  • 152
  • 198