こんにちは、さまざまな URL から製品の価格を取得しようとしています。コンテンツを取得する方法は知っていますが、正規表現関数を書くのが苦手です。誰かが私を書いてくれませんか。$ の後の任意の数字と一致する必要があります。たとえば、「$40」、「$40.95」、「$ 45」などです。
ありがとうございました
$string = '
Hi! This answer will cost you $10.
If you do not vote this answer up, it will cost you another in $1.23 or $ 2.45.
Be good and transfer me arround $12.45 bucks to my IBAN SI56 1234 4567 8901 234.
Just joking, it is for free ;-)
';
preg_match_all('~(\$\h?\d+(\.\d+)?)~', $string, $matches);
echo "<pre>".print_r($matches[1],true)."</pre>";
これは出力されます:
Array
(
[0] => $10
[1] => $1.23
[2] => $ 2.45
[3] => $12.45
)
以下を使用できます。
/(\$[0-9]+(\.[0-9]+)?)/