php preg_match() を php に記述して 250 の値を取得するにはどうすればよいでしょうか。250 を選択したい html コードの大きな文字列があり、正規表現を正しく取得できないようです。
これは、一致させたい html パターンです。250 の整数を抽出したいことに注意してください。
<span class="price-ld">H$250</span>
私はこれを行うために何時間も試みてきましたが、うまくいきません笑
php preg_match() を php に記述して 250 の値を取得するにはどうすればよいでしょうか。250 を選択したい html コードの大きな文字列があり、正規表現を正しく取得できないようです。
これは、一致させたい html パターンです。250 の整数を抽出したいことに注意してください。
<span class="price-ld">H$250</span>
私はこれを行うために何時間も試みてきましたが、うまくいきません笑
preg_match('/<span class="price-ld">H$(\d+)<\/span>/i', $your_html, $matches);
print "Its ".$matches[1]." USD";
正規表現は実際にはコードに依存します。正確にはどこを探していますか?
これはあなたが探している正規表現です:
(?<=<span class="price-ld">H\$)\d+(?=</span>)
結果はこちらでご覧いただけます。
そして、ここに説明があります:
Options: case insensitive; ^ and $ match at line breaks
Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=<span class="price-ld">H\$)»
Match the characters “<span class="price-ld">H” literally «<span class="price-ld">H»
Match the character “$” literally «\$»
Match a single digit 0..9 «\d+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=</span>)»
Match the characters “</span>” literally «span>»