duanguan3863 2011-10-30 21:40
浏览 41

使用php在txt文件中的值之间提取文本

Im trying to extract the values between eng_tid

and eng_data for http://fdguirhgeruih.x10.mx/html.txt and I keep getting T string errors.

why do I keep getting errors

<? php

    //First, open the file. Change your filename
    $file = "http://fdguirhgeruih.x10.mx/html.txt";
    $word1='tid';
    $word2='data';


    $handle = fopen($file, "r");
    $contents = fread($handle, filesize($file));
    fclose($handle);

    $between=substr($contents, strpos($contents, $word1), strpos($contents, $word2) - strpos($contents, $word1));

    echo $between; 


    ?>
  • 写回答

1条回答 默认 最新

  • duankanyi6539 2011-10-30 21:45
    关注

    UPDATE after seeing error messages...

    Instead of fread() and attempting to use the size in bytes of your target file, you may simply use file_get_contents() to retrieve the remote file. Your error is because PHP wants to read the filesize of the file as though it is local, but it is a remote file over HTTP. filesize() reports 0 and an error. Instead do

    // Don't do this...
    //$handle = fopen($file, "r");
    //$contents = fread($handle, filesize($file));
    //fclose($handle);
    
    // Instead do this...
    $contents = file_get_contents($file);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?