Re: Parsing HTML files
| From: | Peter Brodersen | Date: | Fri, 10 Sep 2004 23:33:14 +0000 |
| Subject: | Re: Parsing HTML files | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196372@lists.php.net to get a copy of this message | ||
On Fri, 10 Sep 2004 11:58:58 +0100, in php.general
abdulwahid@gmail.com (Abdul-Wahid Paterson) wrote:
>> I was wondering if any classes/functions could help me with this little
>> challenge, (im hopeless at regex ;-)
>>
>> <input type="hidden" name="id" value="593" />
>
>No easy way of doing it, regex somthing like:
>
>$id = preg_replace("/.*<input.*name=\"id\" value=\"[0-9]+\"
>\/>/", $1, $string);
How about just using an xml-based function? Much cleaner, doesn't
require name-attribute to be present before value-attribute.
<?php
$string = '<input type="hidden" name="id" value="593"
/>';
$x = xml_parser_create();
xml_parse_into_struct($x,$string,$array);
print $array[0]['attributes']['VALUE'];
// or, out of curiousity:
var_dump($array);
?>
(and why preg_replace? $1 wouldn't even be set since no capturing
parenthesises are used)
--
- Peter Brodersen