0

我成功地从字符串中提取整数。

怎么做,但包括字符串:“k”、“m”和“b”?

此代码采用给定的网站代码并提取数字,我需要数字和“k”、“m”和“b”

$objectId = 15259;
$lines = file('http://testwebsite.com?obj=' . $objectId);
foreach ($lines as $line_num => $line) {
    $lineCrawl = htmlspecialchars($line);
    $stringSum = "$stringSum$lineCrawl";
}

function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
}

$parsed = get_string_between($stringSum, "Current guide price", "Today");

$guideprice = ereg_replace("[^0-9]", "", $parsed); 

echo $guideprice; 
4

2 回答 2

1

更改0-90-9kmb应该工作

于 2012-05-01T22:26:48.263 回答
0

更改代码以更好地使用正则表达式:

<? //PHP 5.4+
$matches = [];
\preg_match(
    <<<'REGEX'
`(?x)
    Current \s guide \s price
    \D* (?<price> \d+ [kmb] \s )
    Today
`u
REGEX
,   \file_get_contents('http://testwebsite.com?obj=' . 15259),
    $matches
);
echo $matches['price'];
?>
于 2012-05-02T04:41:02.557 回答