I am trying to find a way to match something inside a match. I am still reading oreilly's book on regular expressions, but this is something I have to do now:
I need to get all the values from the inputs inside a form. The page contains multiple forms, so normally I would do something similar to this:
type="checkbox" value="([^"])"
But now I need to target all the checkbox values inside the specific form. Using preg_match by the way.
ps I know I could get the form with preg_match first, and the match inside that result, but I'm wondering how to do this in regex.
preg_match("|type=\"checkbox\" value=\"(.*?)\"|");
You really shouldn't be using regular expressions to parse HTML. Look into the HTML DOM Parser . Using this your code becomes very simple.
$html = file_get_html('http://www.website.com/');
$form = $html->find('#formId')
foreach($form->find('input[type=checkbox]') as $element) {
//Do what you need to do
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.