以下のような文字列変数があり、2つの数字を持つ文字列があります
EUR 66,00 + EUR 3,90 Versandkosten
私は2つの数値exを抽出する必要があります-66,00と3,98の両方を2つの変数に別々に抽出します。誰でもこれを行う方法を教えてもらえますか
私は2つの数値exを抽出する必要があります-66,00と3,98の両方を2つの変数に別々に抽出します。誰でもこれを行う方法を教えてもらえますか
PHP でこれを行う方法はたくさんあります。ここにカップルがあります。
1. sscanf($subject, 'EUR %[0-9,] + EUR %[0-9,]', $one, $two);
2. preg_match_all('/[\d,]+/', $subject, $matches); list($one, $two) = $matches[0];
文字列が常に次のように見える場合は、次のような正規表現が機能するはずです。
$string = "EUR 66,00 + EUR 3,90 Versandkosten";
preg_match("/([0-9,]+).+([0-9,]+)/", $string, $matches);
var_dump($matches[1], $matches[2]);
この文字列を考慮して
$string = 'EUR 66,00 + EUR 3,90 Versandkosten';
$ar=explode($string,' ');
$a=$ar[1];
$b=$ar[4];
preg_match('#([0-9,]+).*?([0-9,]+)#', $String, $Matches);
あなたの番号が入っ$Matches[1]
て$Matches[2]
これは正しいものです:
<pre>
<?php
// 1The given string
$string = 'EUR 66,00 + EUR 3,90 Versandkosten';
// 2Match with any lowercase letters
$pattern[0] = '/[a-z]/';
// 3Match with any uppercase letters
$pattern[1] = '/[A-Z]/';
// 4Match with any commas
$pattern[2] = '/(,)/';
// 5Match with any spaces
$pattern[3] = '/( )/';
// 6 Remove the matched strings
$stripped = preg_replace($pattern,'',$string);
// Split into array from the matched non digit character + in this case.
$array = preg_split('/[\D]/',$stripped);
print_r($array);
?>
</pre>