Hi I have an API which return me form values in a string: <input name="field1" value="xx"/> <input name="field2" value="yy"/> The form is stored in a string. Is there a way to extract the value(xx & yy) by the input name?
<?php $string = <<<eof <input name="field1" value="xx"/> <input name="field2" value="yy"/> eof; preg_match_all('~<input name="field([1-2]*)" value="(.+)"/>~', $string, $values); $xx = $values[2][0]; $yy = $values[2][1]; ?> PHP:
hi danx10 i tried ur code can't seem to work. Basically i need something like this: <?php $string = ' <input name="field1" value="xx"/> <input name="field2" value="yy"/> '; echo $extractinput->extract($string, "field1"); ?> how do i make the extract function based on field name and html string?
My code works fine: <?php $string = <<<eof <input name="field1" value="xx"/> <input name="field2" value="yy"/> eof; preg_match_all('~<input name="field([1-2]*)" value="(.+)"/>~Us', $string, $values); $xx = $values[2][0]; $yy = $values[2][1]; echo $xx; ?> PHP: $values contains an array, theirfore no matter how many input tags you have you'll always have the value of the input within the array, so use your php knowledge to extract specific values from the array. (just like I've done with $xx and $yy), you can read about arrays on the php website here However if you need further assistance, just reply