It will work and very flexible. All that is required is that the attribute valueappears after the attribute namein the element hosted_button_id. Modifiers sand mallow you to match multiple lines. That way you can essentially map the entire html page, not just the element hosted_button_id.
$str = '<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="DJ445KDUWP402">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>';
preg_match('/name="hosted_button_id".*?value="(.*?)".*?>/ims', $str, $matches);
:
Array
(
[0] => name="hosted_button_id" value="DJ445KDUWP402">
[1] => DJ445KDUWP402
)
.
preg_match_all('/<input .*?name="(.*?)" .*?value="(.*?)".*?>/ims', $str, $matches);
print_r($matches);
:
Array
(
[0] => Array
(
[0] => <input type="hidden" name="cmd" value="_s-xclick">
[1] => <input type="hidden" name="hosted_button_id" value="DJ445KDUWP402">
)
[1] => Array
(
[0] => cmd
[1] => hosted_button_id
)
[2] => Array
(
[0] => _s-xclick
[1] => DJ445KDUWP402
)
)