0

I have a file, with many parts of code. Each part starts with <form> and ends with </form>. Between each form, there is something like this: <input type='text' name='date' value='2010-01-01'><input type='text' name='username' value='test'>

I want to parse each part of the code with php and get the value of input username, where the value for input date is '2010-01-01'

Any solutions please?

example:

<form>
<input type='text' name='date' value='2010-01-01'>
<input type='text' name='username' value='test'> <!-- How can I get this value ('test')? -->
</form>
<form>
<input type='text' name='date' value='2010-01-02'>
<input type='text' name='username' value='test2'>
</form>
.
.
.
3
  • 2
    start with what? end with what? Commented May 2, 2012 at 8:51
  • @dqlopez start with <form> and end with <form>. Ataomega forgot the ``` and I can't edit because there is a pending edit which needs to be approved first... Commented May 2, 2012 at 9:02
  • Kind of multiple forms? Are you trying to submit each form contents on one submit button? If so, which form has that submit button. Commented May 2, 2012 at 9:30

1 Answer 1

1
preg_match('/form.*name=\'date\' value=\'2010-01-01\'.*name=\'username\' value=\'(.*)\'/Usim', $f, $r);
printf($r[1]);
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for all helps. let me try. could someone please explain this? preg_match('/form.*name=\'date\' value=\'2010-01-01\'.*name=\'username\' value=\'(.*)\'/Usim', $f, $r); printf($r[1]);
Regular expression are not an easy lesson, PHP regex documentation: php.net/manual/en/pcre.pattern.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.