2013-04-11 84 views
0

我捲曲,得到如下結果:抓鬥內捲曲

echo $contents 

,給了我這樣的:

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

$13.32 fee 
$15.22 fee 2 

如何我只是搶1.02 - 在$後和前面的一切</td>

我想通過PHP剝離這一點,並把資金投入到變量$平衡....

任何形式的幫助我都可以得到,非常感謝!

+0

很肯定捲曲是從網頁 – lemondrop 2013-04-11 04:54:13

回答

1

是你可以使用你想要的東西

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

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

我認爲他想要實際值1.02到數組中。 – bestprogrammerintheworld 2013-04-11 05:05:08

1

這可能是做這件事的好方法......但

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

或者你可以使用正則表達式。事情是這樣的:

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

您可以測試正則表達式的位置:RegExpPal

可以使用的preg_match()來解析使用正則表達式的平衡。 preg_match()

+0

獲取數據謝謝你的幫助,但如果我有超過$以上在那個頁面上...我們可以在它前面找到那些字平衡的人嗎? – thevoipman 2013-04-11 04:58:48

+0

與一個正則表達式呀 – 2013-04-11 04:59:26

+0

我不夠聰明瞭解如何/如何處理正則表達式,你能請求提供者更多的指導嗎? – thevoipman 2013-04-11 05:05:08

1

基本上現在你有一個字符串

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

我說得對不對?

現在試試這個:

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

現在,使用爆炸:

$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 
+0

是的,但我在同一頁上有多個「$」......但只有一個餘額爲 – thevoipman 2013-04-11 04:59:44

+0

,那麼您是否知道平衡的位置呢?如果它總是您想要的第一個'$'? – 2013-04-11 05:00:46

+1

我已經更新了上面的問題...我想要的$總是有餘額:在它前面....其他人沒有「餘額:」字樣 – thevoipman 2013-04-11 05:03:11

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 
+0

我試過並變得空白 – thevoipman 2013-04-11 05:14:29

+0

是' 2013-04-11 06:14:49