match string in html file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
playwright
Forum Newbie
Posts: 20
Joined: Wed Jun 02, 2010 6:11 pm

match string in html file

Post by playwright »

Is there a way to search in html file for a specific string and the same string plus some other content? For example:
abc.php?t=123 and also abc.php?t=123&page=2 and abc.php?t=123&page=3. Is there a regex that can do the job along with preg_match()?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: match string in html file

Post by John Cartwright »

Post the entire contents of your html. It is dificult to create the parameters without knowing the boundaries. For instance, most url's are enclosed in quotes, so a simple regex would like like

Code: Select all

preg_match('~(abc\.php[^"]+)~im', $htmlsource, $matches);
Which will capture any string beginning with abc.php until it reaches a double quote.
Post Reply