2

I'm using preg_match_all() and my problem is that I can't create the pattern that I want. Example of source text:

<td align='left'>
    <span style='font-size: 13px; font-family: Verdana;'><span>
</td>
<td>
    <a style='color: #ffff00' rel='gb_page_fs[]' title='Parodyk kitiems 8 seriją' href='/pasidalink-19577x10/'>
        <img src="/templates/filmai_black/images/ico_tool_share.gif" />
    </a>
</td>
<td>
    <small>LT titrai</small>
</td>
<td>
    <a rel='gb_page_center[528, 290]' title='Žiūrėti 8 seriją' href='http://www.filmai.in/watch.php?em=BuwgzpqtssiAGGcjeekz9PTI1NjQ0N2E~'>
        <img src="/templates/filmai_black/images/play_icon.png" width="20" onclick='set_watched_cookie_serial("19577x10", "done-tick-full-series")' />
    </a>
</td>

I am using the pattern:

<td><small>(.*)</small></td>
<td><a rel='gb_page_center[528, 290]' title='Žiūrėti (.*) seriją' href='(.*)'><img src=

I want to get the content in the (.*) location into an array.

Can someone please correct my pattern and explain it? I want to learn to use regular expressions.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
altdovydas
  • 109
  • 1
  • 7
  • 4
    You should never use regex against `html`, use `DOMDocument` instead. – Mihai Iorga Sep 27 '12 at 09:41
  • 1
    Yes, inexperienced coders are floored by regex syntax if it comes to HTML extraction. There are [simpler options](http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php). – mario Sep 27 '12 at 09:57

1 Answers1

0

"Don't use Regex to parse HTML" aside, here are a few uber simple steps to learning Regexp.

  1. Download and install RegexBuddy
  2. Run RegexBuddy
  3. Start with something easy and then FLY! :)

the expression you are looking for is:

<small>(.*)</small>

It finds all characters found inbetween small tags and puts them into backreferences. Think of Backreference as an Array. The first to item found, is 0, next is 1 and so on.

// command:
preg_match_all('%<small>(.*)</small>%i', $subject, $result, PREG_PATTERN_ORDER);

// $result[0]

Array
(
    [0] => <small>LT titrai</small>
)
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51