Php preg_replace form field

I think I should be able to search for an input field html and replace using the code below, where the variable $html contains a text input field with it's value set to [quantity]. However this depends on the value setting preceding the field's closing tag. Can this pattern match be improved to search for html that starts with '<input', ends with '/>' and contains 'value="[quantity]"'?
$new_html = preg_replace('/<input(.*)value="\[quantity\]" \/>/', $quantity, $html);

Open in new window

LVL 1
ncwAsked:
Who is Participating?
 
käµfm³d 👽Commented:
Try this:
$new_html = preg_replace('#<input(?=[^>]*value="\[quantity\]")[^>]*>#', $quantity, $html);

Open in new window

0
 
ncwAuthor Commented:
Yes that worked well thank you.
0
 
ncwAuthor Commented:
Wondered if you could help me with a similar question please at http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_27302936.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.