Reputation: 849
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?
Upvotes: 0
Views: 169
Reputation: 3328
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
)
Upvotes: 1
Reputation: 19397
Try also escaping your inner /
characters:
"/href=\"http:\/\/www.free-tv-video-online.me\/player\/.*\" target=\"_blank\"><div>TV Show Season 2 Episode 1/"
Upvotes: 1
Reputation: 2775
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.
Upvotes: 0