note 88963 added to function.preg-match-all

From: Date: Sun, 15 Feb 2009 21:52:20 +0000
Subject: note 88963 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-150710@lists.php.net to get a copy of this message
I've been using the following to extract the attributes from a tag ... <?php //initiatlise test tag $tag='<input type = "checkbox" checked space="ok with spaces">'; //generate key=>value array with first item as tag name preg_match_all('/(\w+)(?:\s*=\s*"([^"]+)"|)/', $tag, $result); $attributes=array_combine($result[1],$result[2]); //output attribute array echo '<pre>'.print_r($attributes,true).'</pre>'; ?> The above example produces the following array: Array ( [input] => [type] => checkbox [checked] => [space] => ok with spaces) where the first item is the tag name and rest are the attribues and value. It can't cope without quotes so if anyone can make a concise suggestion it would be very helpfull! i.e. name=test or [color=blue doesn't work but name="test" and [color="blue" does work. ---- Server IP: 87.124.35.190 Probable Submitter: 86.20.253.113 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- https://master.php.net/note/edit/88963 Del: integrated -- https://master.php.net/note/delete/88963/integrated Del: useless -- https://master.php.net/note/delete/88963/useless Del: bad code -- https://master.php.net/note/delete/88963/bad+code Del: spam -- https://master.php.net/note/delete/88963/spam Del: non-english -- https://master.php.net/note/delete/88963/non-english Del: in docs -- https://master.php.net/note/delete/88963/in+docs Del: other reasons-- https://master.php.net/note/delete/88963 Reject -- https://master.php.net/note/reject/88963 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150710) next »