第4章 數(shù)據(jù)處理-php正則表達(dá)式-鄭阿奇(續(xù))
704
2023-12-09
用file_get_contents()抓取了 這個(gè)網(wǎng)址上的內(nèi)容
http://simonfenci.sinaapp.com/index.php?key=simon&wd=1314abc
看似好像反回的是數(shù)組。。但是我不管怎么用foreach循環(huán)都報(bào)錯(cuò)。。
我只想把數(shù)組中的word里面的值 取出來。
方法如下:正解(其他的字段一樣,把word替換即可)
$s=file_get_contents('http://simonfenci.sinaapp.com/index.php?key=simon&wd=1314abc');$rule='#(?<=[word] =>)sw+#';preg_match_all($rule,$s,$arr);print_r($arr);
我的遇到的問題如下:
<?php @header('content-type:text/html;charset=utf-8'); function show_bug($msg){ echo "<pre>"; print_r($msg); echo "</pre>"; } //ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)'); //$url="http://redhatcn.cn//Home/Login/mmzh2/t/user"; // 所有[jb] => 后面的金額,所有金額相加 $url='array.txt'; $s=file_get_contents($url); $rule='#(?<=[jb] =>)sw+#';preg_match_all($rule,$s,$arr); // $bool=is_array($arr); // var_dump($bool); //show_bug($arr); $arr_num=$arr[0]; //array_sum函數(shù)返回?cái)?shù)組中所有值的總和。 echo '文件中所有jb之和為:'.array_sum($arr_num); ?>
array.txt內(nèi)容如下所示:
Array( [0] => Array ( [id] => 183 [cf] => 0 [date] => 2016-08-26 21:17:32 [zffs1] => 0 [zffs2] => 1 [zffs3] => 0 [jb] => 5000 [zt] => 1 [user] => 18676081117 [qr_zt] => 1 [user_tjr] => 18943636615 [user_nc] => ¿ÉÀÖ [cf_ds] => 0 [jycg_ds] => 0 [yid] => [ok] => 1 ) [1] => Array ( [id] => 240 [cf] => 0 [date] => 2016-09-03 12:06:50 [zffs1] => 1 [zffs2] => 1 [zffs3] => 1 [jb] => 8000 [zt] => 0 [user] => 15192777617 [qr_zt] => 0 [user_tjr] => 13987611435 [user_nc] => Ö콨¸Û [cf_ds] => 0 [jycg_ds] => 0 [yid] => [ok] => 1 ) )
以上這篇php file_get_contents取文件中數(shù)組元素的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持綠夏網(wǎng)。
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請用戶自負(fù)。本站信息來自網(wǎng)絡(luò)收集整理,版權(quán)爭議與本站無關(guān)。您必須在下載后的24個(gè)小時(shí)之內(nèi),從您的電腦或手機(jī)中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請支持正版,購買注冊,得到更好的正版服務(wù)。我們非常重視版權(quán)問題,如有侵權(quán)請郵件[admin@lxwl520.com]與我們聯(lián)系進(jìn)行刪除處理。敬請諒解!