dqxboe2628 2011-05-02 09:54
浏览 32
已采纳

PHP使用file_get_contents爆炸函数?

   <?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>

The above code prints an array as an output.

If I use

<?php
$homepage = file_get_contents('http://www.example.com/data.txt');
print_r (explode(" ",$homepage));
    ?>

However it does not display individual numbers in the text file in the form of an array.

Ultimately I want to read numbers from a text file and print their frequency. The data.txt has 100,000 numbers. One number per line.

  • 写回答

5条回答 默认 最新

  • doumao1917 2011-05-02 09:59
    关注

    A new line is not a space. You have to explode at the appropriate new line character combination. E.g. for Linux:

    explode("
    ",$homepage)
    

    Alternatively, you can use preg_split and the character group \s which matches every white space character:

    preg_split('/\s+/', $homepage);
    

    Another option (maybe faster) might be to use fgetcsv.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测