dongpai6567 2015-06-07 06:26
浏览 322
已采纳

如何使用php regex将文本放在两个垂直条内

I'm trying to get the text inside two vertical bars of json string.I'm parsing wikipedia data and new to json.The structure is weird.Any help?

 {{Infobox အတ္ထုပ္ပတ္တိ
 | အမည် =စိုးသူ 
 | ဓာတ်ပုံ =Soe Thu.jpg
 | သက်တမ်း = 
 | မွေးသက္ကရာဇ် = [[နိုဝင်ဘာ]] ၃၀ ရက်
 | အမည်ရင်း =စိုးသူလွင် 
 | မိဘအမည် =ဦးခင်မောင်လွင်+ဒေါ်ခင်သူဇာ
 | မွေးဖွားရာဒေသ= 
 | နိုင်ငံသား =[[Image:Flag of Myanmar.png|25px]] မြန်မာ
 | လူမျိုး =ဗမာ
 | ကိုးကွယ်သည့်ဘာသာ =ဗုဒ္ဓဘာသာ
 | ပညာအရည်အချင်း = M.B;B.S
 | အလုပ်အကိုင် = ဆရာဝန် ရုပ်ရှင်သရုပ်ဆောင်၊ အဆိုတော်
 | ကြင်ဖော် = ခင်မြမြဝတ်မှုန်ဆွေ
 | သားသမီး =
 | ထင်ပေါ်ကျော်ကြားမှု =အကယ်ဒမီရ မင်းသား
 | ထင်ရှားသည့်လက်ရာများ=
 | ရရှိခဲ့သည့်ဘွဲ့တံဆိပ်များ=မြန်မာ့ ရုပ်ရှင် ထူးချွန်ဆု
 | ကွယ်လွန်ရက် =
 | ကွယ်လွန်ရာဒေသ=
 | လက်မှတ်=
 | ကွန်ယက် =http://www.facebook.com/pages/Soe-Thu
  }}

I've tried this in php.

 $result=explode("|",$str);
  var_dump($result);

But I don't think it is a correct way.

  • 写回答

1条回答 默认 最新

  • dpkk8687 2015-06-07 06:33
    关注

    you can use this regex

    (?<=\|)[^|]+(?=\|)
    

    check the demo Here

    I noticed that you have this text [[Image:Flag of Myanmar.png|25px]]

    so you can use this regex also , because | in Myanmar.png|25px may cause problems in your case

    (?<=\|).+?(?=\|\W)
    

    check this Demo Here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制