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 使用wpf制作打砖块游戏时遇到的一个Bug
  • ¥15 qrCodeDetector.detectAndDecode
  • ¥15 海洋可控源和大地电磁一维联合反演
  • ¥15 MFC多文档程序获取视图指针问题
  • ¥20 解体如何编写程序还有运行结果截图
  • ¥15 如何把matlabR2023遗传算法工具箱里面的各类选项对应的代码调出来呢?
  • ¥30 MDIGetActive() 获取活动view
  • ¥15 有数据,如何安装使用CLIP模型检索图片
  • ¥15 lingo代码报错无法运行,如何解决,如果能解决请提供能够运行的lingo代码
  • ¥100 读取 IMU BNO080 数据