witam, w jaki sposób mogę z takiego czegoś wcyiagnąć tylko liczby ?
<test>output: 1;outdoor: 456;<test>
<test>output: 2;outdoor: 4564;<test>
<test>output: 3;outdoor: 645;<test>
<test>output: 4;outdoor: 765;<test>
witam, w jaki sposób mogę z takiego czegoś wcyiagnąć tylko liczby ?
<test>output: 1;outdoor: 456;<test>
<test>output: 2;outdoor: 4564;<test>
<test>output: 3;outdoor: 645;<test>
<test>output: 4;outdoor: 765;<test>
Regexem
fasadin napisał(a):
Regexem
a w jaki sposób do tego zrobić np update bazy?
<test>output: 1;outdoor: 456;<test>
<test>output: 2;outdoor: 4564;<test>
<test>output: 3;outdoor: 645;<test>
<test>output: 4;outdoor: 765;<test>
cos takiego chciałbym osiągnąć:
mysql_query("UPDATE test SET outdoor = $outdoor" where id = $output);
Na pewno jakbyśmy znali całość problemu dałoby się to inaczej napisać (bardziej optymalnie), ale w twoim przypadku mogłoby to być coś takiego:
$string="<test>output: 1;outdoor: 456;<test> <test>output: 2;outdoor: 4564;<test> <test>output: 3;outdoor: 645;<test> <test>output: 4;outdoor: 765;<test>";
preg_match_all("/\d+/",$string,$matches);
$matches=$matches[0];
$output=array('indexes'=>array(),'values'=>array());
foreach($matches as $key=>$match)
{
if($key%2) { $output['values'][]=$match; } else { $output['indexes'][]=$match; }
}
foreach($output['indexes'] as $key=>$out)
{
$query="UPDATE test SET outdoor =".$output['values'][$key]." where id = ".$out;
}
$string = "<test>output: 1;outdoor: 456;<test> <test>output: 2;outdoor: 4564;<test> <test>output: 3;outdoor: 645;<test> <test>output: 4;outdoor: 765;<test>";
$output = array();
preg_match_all("/output: ([0-9]+);outdoor: ([0-9]+);/",$string,$out);
$query = '';
$i = 0;
foreach($out[1] as $index) {
$output[$index] = $out[2][$i];
$i++;
}
foreach($output as $id => $value) {
$query .= "UPDATE test SET outdoor = $value where id = ".$id."; ";
}