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?

1
  • So the html file contains valid HTML? then regex should not be used. Commented Jul 13, 2022 at 8:54

3 Answers 3

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
)
Sign up to request clarification or add additional context in comments.

1 Comment

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
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/"

1 Comment

I think that may be it because I know that / are used to define new patterns in regular expressions.
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.

2 Comments

I'm really sorry I think that is a product of improper translation on my behalf. I just updated the original question.
That pattern matches the string you provided. What else do you require?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.