note 34805 added to pcre.pattern.syntax
| From: | paul at ue dot com dot br | Date: | Thu, 07 Aug 2003 07:31:18 +0000 |
| Subject: | note 34805 added to pcre.pattern.syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53554@lists.php.net to get a copy of this message | ||
You can use PREG to create a MYSQL QUERY from XML...
<?
$content .= "<test>\n";
$content .= " <name>gh</name>\n";
$content .= " <cell>909</cell>\n";
$content .= "</test>\n";
$content .= "<test>\n";
$content .= " <name>ddd</name>\n";
$content .= " <cell>456756756745</cell>\n";
$content .= "</test>\n";
$content .= "<xxx>\n";
$content .= " <name>vbn</name>\n";
$content .= " <cell>343434</cell>\n";
$content .= " <aaa>3sdf34</aaa>\n";
$content .= " <bbb>3sdf34</bbb>\n";
$content .= " <ccc>3sdf34</ccc>\n";
$content .= "</xxx>\n";
preg_match_all ("/<(.*?)>(.*?)<\/\\1>/is", $content, $tag);
while (list($k, $v) = each($tag[2]))
{
$names = $values = "";
preg_match_all ("/<(.*?)>(.*)<\/\\1>/i", $v, $out);
while (list($j, $v2) = each($out[2]))
{
if ($names) $names .= ", ";
$names .= $out[1][$j];
if ($values) $values .= ", ";
$values .= "'".$out[2][$j]."'";
}
if (($names) && ($values))
{
echo $query = "INSERT INTO ".$tag[1][$k]." ($names) VALUES ($values)\n";
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/pcre.pattern.syntax.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34805
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34805&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34805&report=yes