...<img src="/img_box/wind-13x13/w045.gif" alt="NE" width="13" height="13" /> 22 kmh </p>... PHP: I want to get the speed (here it is 22). My idea is to get second and third charecters before kmh. But i don not have an idea how to do it? Can you help me? note: "/img_box/wind-13x13/w045.gif", "NE" and "22" are not static.
solved echo "<br>"; <? $data = "The party will start at 22 kmh"; preg_match_all('/(\d+)\s*(kmh|kml)/', $data, $match, PREG_PATTERN_ORDER); echo "Full: <br>"; print_r($match[0]); echo "<p>Raw: <br>"; print_r($match[1]); echo "<p>Tags: <br>"; print_r($match[2]); ?> PHP: output: Full: <br>Array ( [0] => 22 kmh ) <p>Raw: <br>Array ( [0] => 22 ) <p>Tags: <br>Array ( [0] => kmh ) HTML:
I would add the <img> marker before the \d so the pattern is more specific. /<img[^>]+>\s*(\d+)\s*(kmh|kml)/is Code (markup):