douxiji8707 2014-09-16 22:02
浏览 42

将代码拆分为某些变量

sorry for any mistake i am beginner on php i got this value and want split the usa address from the code

Service Address

GERTRUDE HAGAMAN 
 2608 N LAKEVIEW DR
HAMMONTON, NJ 08037-3501 

Manage XFINITY WiFi 
Manage Xfinity wifi home hotspot setting

i need extract to be

$name :    GERTRUDE HAGAMAN 
$address : 2608 N LAKEVIEW DR
$city    : HAMMONTON
$state   : NJ 
$zipcode : 08037-3501 

so is there any advice

  • 写回答

1条回答 默认 最新

  • dongshan1811 2014-09-16 22:55
    关注
    <?php
    preg_match('/service address
    *(.*)
    *(.*)
    ((.*?),\s+(\w{2})\s+(.*))
    *manage xfinity wifi/i', $full_address, $match);
    
    $name = $match[1];
    $address = $match[2];
    $city = $match[4];
    $state = $match[5];
    $zip = $match[6];
    ?>
    

    this will only work if the address format is similar to what you have posted above

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口