doubo4336 2014-09-16 18:30
浏览 23
已采纳

php从网站读取列表到数组

I have a list of products codes that i wish to read into an array using php.

the list is to be fetched from a website and has over 700 items looks something like this:

4310ABC
4590DEF
8950GHK

What i want to do is put every code into a php array like so:

php_array ( [0] => 4310ABC 
            [1] => 4590DEF 
            [2] => 8950GHK)

This is what i have:

$php_array = file_get_contents('http://anysite.net/product_codes.php');
print_r (explode("
",$php_array));

But my result is :

Array ( [0] => 4310ABC
               4590DEF
               8950GHK)

I have tried explode, preg_split('/[ ]+/', $php_array); but nothing seems to do the trick. Can anyone give me some pointers? thanks!

  • 写回答

2条回答 默认 最新

  • dou91736 2014-09-16 18:46
    关注

    The lines are separated by a br, so use this instead:

    $php_array = file_get_contents('http://anysite.net/product_codes.php');
    print_r (explode("<br>",$php_array));
    

    Don't forget to change the br to however it's spelled within the document you are fetching, for example it's often spelled like this:

    <br />
    

    Which is the most correct way to write it.

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

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同