Solved

Php preg_replace form field

Posted on 2011-09-09
3
454 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:ncw
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36512065
Try this:
$new_html = preg_replace('#<input(?=[^>]*value="\[quantity\]")[^>]*>#', $quantity, $html);

Open in new window

0
 
LVL 1

Author Closing Comment

by:ncw
ID: 36521876
Yes that worked well thank you.
0
 
LVL 1

Author Comment

by:ncw
ID: 36521994
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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question