php-file_get_contents取文件中数组元素的用法
2016-09-05 18:20
597 查看
用file_get_contents()抓取了 这个网址上的内容
http://simonfenci.sinaapp.com/index.php?key=simon&wd=1314abc
看似好像反回的是数组。。但是我不管怎么用foreach循环都报错。。
我只想把数组中的word里面的值 取出来。
方法如下:正解(其他的字段一样,把word替换即可)
我的遇到的问题如下:
array.txt内容如下所示:
参考链接:
http://bbs.csdn.net/topics/390960440?page=1#post-401552660
http://simonfenci.sinaapp.com/index.php?key=simon&wd=1314abc
看似好像反回的是数组。。但是我不管怎么用foreach循环都报错。。
我只想把数组中的word里面的值 取出来。
方法如下:正解(其他的字段一样,把word替换即可)
我的遇到的问题如下:
<?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\] =>)\s\w+#';
preg_match_all($rule,$s,$arr); // $bool=is_array($arr); // var_dump($bool); //show_bug($arr); $arr_num=$arr[0]; //array_sum函数返回数组中所有值的总和。 echo '文件中所有jb之和为:'.array_sum($arr_num); ?>
array.txt内容如下所示:
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 ) )
参考链接:
http://bbs.csdn.net/topics/390960440?page=1#post-401552660
相关文章推荐
- php使用Url读取文件的内容及file_get_contents用法
- file_put_contents以及file_get_contents的用法与在使用过程中遇到的问题(PHP学习)
- php 使用file_get_contents读取大文件的方法
- php读取网络文件 curl, fsockopen ,file_get_contents 几个方法的效率对比
- php读取网络文件 curl, fsockopen ,file_get_contents 几个方法的效率对比
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- file_put_contents以及file_get_contents的用法与在使用过程中遇到的问题(PHP学习)
- php中的 file_get_contents(‘php://input’)用法
- PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
- php读写文件比较 (fread,fwrite,file_put_contents,file_get_contents)
- php读取网络文件 curl, fsockopen ,file_get_contents 几个方法的效率对比
- PHP读取文件所有内容到字符串 file_get_contents
- php 在linux 用fopen() 函数打开,file_get_contents(),fread()函数 读取 另外一台服务器映射过来的文件 总是返回false,null的情况。
- PHP文件操作,多行句子的读取,file()函数,file_get_contents()函数,file_put_contents()函数,is_file,统计网站pv (访问量),文件的复制 copy
- php读取本地文件常用函数(fopen与file_get_contents)
- php 使用file_get_contents读取大文件的方法
- PHP读取文件函数fread,fgets,fgetc,file_get_contents和file函数的使用总结
- php读取网络文件curl,fsockopen,file_get_contents,file,fopen几种方法
- 【php】PHP远程读取大文件之file_get_contents()与readfile()效率比较
- windows nginx使用file_get_contents、fopen、curl访问php文件造成阻塞的解决办法