duanpanzhu2910 2013-08-13 12:59
浏览 19
已采纳

PHP将文本分解为数组[关闭]

I am trying to convert the contents of this link (only the Country/code list) into an array. To do so I tried using explode(), but exploding on , , , or doesn't work.

Anybody knows what they are using? I only need the country name and the 2 letter-code.

  • 写回答

5条回答 默认 最新

  • dongyan1899 2013-08-13 13:04
    关注

    consider using this page instead - http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt.htm

    or in XML http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_xml.htm

    as it will be easier to parse!

    To do it programmatically...

    $country_arr = [];
    $raw = file_get_contents("http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt.html");
    $lines = explode("
    ",$raw);
    foreach ($lines as &$line) {
        $bits = explode(";",$line);
        $country_arr[$bits[0]] = $bits[1];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

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