0

Hey guys I'm parsing a bunch of data from an html file in PHP using the preg_match_all($pattern, $htmlPage, $matches) method (regular expressions) and am having some issues creating the pattern for the following string: href="http://www.free-tv-video-online.me/player/putlocker.php?id=12VT1372H42OKWGKW" target="_blank"><div>TV Show Season 2 Episode 1.

The pattern consists of two strings with a wildcard string in the middle. This should be fairly simple but I am having trouble escaping the proper characters in the strings on either side of wildcard string. Here is an example of a pattern I have tried.

//Pattern escaping " and < charecters
$patern = "/href=\"http://www.free-tv-video-online.me/player/.*\" target=\"_blank\">\<div>TV Show Season 2 Episode 1/";

I have tried a couple other patterns but all failed. In all attempts I use the regular expression .* to signify the wildcard string. What is the correct pattern to parse all occurrences of this string out of an HTML file?

ScottOBot
  • 839
  • 3
  • 16
  • 37

3 Answers3

1

Try also escaping your inner / characters:

"/href=\"http:\/\/www.free-tv-video-online.me\/player\/.*\" target=\"_blank\"><div>TV Show Season 2 Episode 1/"
DavidRR
  • 18,291
  • 25
  • 109
  • 191
1

http://www.phpliveregex.com/p/2lc

preg_match("/href=\"http\:\/\/www\.free\-tv\-video\-online\.me\/player\/.*\" target=\"_blank\">\<div>TV Show Season 2 Episode 1/", 'href="http://www.free-tv-video-online.me/player/putlocker.php?id=12VT1372H42OKWGKW" target="_blank"><div>TV Show Season 2 Episode 1', $output);

$output will look like this:

Array
(
    [0] => href="http://www.free-tv-video-online.me/player/putlocker.php?id=12VT1372H42OKWGKW" target="_blank"><div>TV Show Season 2 Episode 1
)
bagonyi
  • 3,258
  • 2
  • 22
  • 20
  • Yeah I figured it out, I used the pattern outlined above. It didn't work at first but I took another look at the HTML page and I was missing some `\n` and `\t` characters but I got it to work! Thanks @bagonyi – ScottOBot Dec 02 '13 at 17:57
0

You added an extra /. 9th character on the second pattern. Just take it out.

Edit: Now the first pattern since you've edited the original post.

brian
  • 2,745
  • 2
  • 17
  • 33