从Curl抓住

时间:2013-04-11 04:50:58

标签: php curl stripping

我卷曲并得到以下内容:

echo $contents

给了我这个:

 <td class="fomeB1" >Balance: $ 1.02</td>

$13.32 fee
$15.22 fee 2

我如何抓住1.02 - $ {和</td>前面的所有内容

我想通过php删除它并将钱存入变量$ balance ....

非常感谢我能得到的任何帮助!

4 个答案:

答案 0 :(得分:1)

这可能是一种不好的方式......但是

$pieces = explode("$ ", $contents);
$pieces = explode("</td>", $pieces[1]);
$balance = $pieces[0];

或者您可以使用正则表达式。像这样:

\$\s\d+.{1}\d+

您可以在此处测试正则表达式:RegExpPal

您可以使用preg_match()使用正则表达式解析余额。 preg_match()

答案 1 :(得分:1)

现在基本上你有一个字符串

$str = '<td class="fomeB1" >Balance: $ 1.02</td>';

我是对的吗?

现在试试这个:

$txt = getTextBetweenTags($str, "td");
echo $txt;//Balance: $ 1.02

现在,请使用explode:

$pieces = explode($txt,' $ ');
echo $pieces[0]; //Balance:
echo $pieces[1]; //1.02

UPDATE: 尝试这个,如果爆炸适用于字符串,它应该工作:

$pieces = explode("Balance: $ ", $str);
$pieces = explode("</td>", $pieces[1]);
$balance = $pieces[0]; //1.02

答案 2 :(得分:1)

是的,你可以使用你想要的东西

preg_match("/(?<=Balance: ).*?(?=<)/", "<td class='fomeB1'>Balance: $ 1.02</td>", $match);
print_r(str_replace("$"," ",$match));

// Prints:
Array
(
    [0] =>   1.02
)

答案 3 :(得分:1)

$str = '<td class="fomeB1" >Balance: $ 1.02</td>';  
$r1 = preg_replace('/.*?\$[ ](.*?)<.*/', '\1',  $str); //match between after first '$ ' ,and first '<' ;
echo $r1; //1.02

$r2= preg_replace('/^<td class="fomeB1" >Balance\: \$ (.*?)<\/td>$/', '\1',  $str); //match between after <td class="fomeB1" >Balance: $    and </td>

echo $r2; //1.02

或更新

$str = ' <td class="fomeB1" >Balance: $ 1.02</td>

$13.32 fee
$15.22 fee 2';  

$r1 = preg_replace('/.*?\$[ ](.*?)<.*/s', '\1',  $str); //match between after first '$ ' ,and first '<' ;
echo $r1.'<br>'; //1.02