playwright Posted June 4, 2010 Share Posted June 4, 2010 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()? Quote Link to comment https://forums.phpfreaks.com/topic/203908-match-string-in-html-file/ Share on other sites More sharing options...
cags Posted June 5, 2010 Share Posted June 5, 2010 Depends how rigidly you can actually define the requirement. Given the examples you have it's hard to say as you don't specify an example input, but you would match the first part with the pattern. abc\.php\?t=123 Depending on how the 'links' are listed in your page you could then use something like.... [^"]* // or \S* ... to match the rest of the query_string. Effectvely giving you a pattern such as... #abc\.php\?t=123[^"]*# Quote Link to comment https://forums.phpfreaks.com/topic/203908-match-string-in-html-file/#findComment-1068157 Share on other sites More sharing options...
playwright Posted June 5, 2010 Author Share Posted June 5, 2010 ok i will be more specific..the code is this one: <a class="paginationLink" href="showthread.php?t=123&page=2" title="Display results">2</a> I want to be able to use a regex or something else so as to grab all href like this one (and also showthread.php?t=123&page=3 and showthread.php?t=123) and then use file_get_contents() to grab contents from all these files. Quote Link to comment https://forums.phpfreaks.com/topic/203908-match-string-in-html-file/#findComment-1068172 Share on other sites More sharing options...
cags Posted June 5, 2010 Share Posted June 5, 2010 In which case the pattern I gave you should be right. Quote Link to comment https://forums.phpfreaks.com/topic/203908-match-string-in-html-file/#findComment-1068182 Share on other sites More sharing options...
ZachMEdwards Posted June 5, 2010 Share Posted June 5, 2010 $pattern = '/(.+\.php\?t=\d+(?:.?&page=\d+)?)/'; Quote Link to comment https://forums.phpfreaks.com/topic/203908-match-string-in-html-file/#findComment-1068276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.