doushichi3678 2012-07-21 16:16
浏览 48
已采纳

用PHP正则表达式从电子邮件中读取链接的问题

I'm having this very weird problem, and I can't seem to figure it out.

I have a script that reads an email and grabs a username and a link (or multiple links) from the email and puts it into an array. For some reason, the links keep getting chopped off because a "= " keeps getting added for some reason. When I do a string replace on the email, before i do the regex, it doesn't replace "= ". Any idea what this problem could be??

Here is the sample email:

 @bill
 http://techcrunch.com/2012/07/20/kickstarter-flashr-wants-to-make-the-iphones-bezel-a-massive-notification-light/?grcc=88888Z0ZwdgtZ0Z0Z0Z0Z0&grcc2=835637c33f965e6cdd34c87219233711~1342828462249~fca4fa8af1286d8a77f26033fdeed202~510f37324b14c50a5e9121f955fac3fa~1342747216490~0~0~0~0~0~0~0~0~7~3~

When I echo out the body of the message I get:

 --00248c6a671acfdb9c04c558d753 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable @bill http://techcrunch.com/2012/07/20/kickstarter-flashr-wants-to-make-the-iphon= es-bezel-a-massive-notification-light/?grcc=3D88888Z0ZwdgtZ0Z0Z0Z0Z0&grcc2= =3D835637c33f965e6cdd34c87219233711~1342828462249~fca4fa8af1286d8a77f26033f= deed202~510f37324b14c50a5e9121f955fac3fa~1342747216490~0~0~0~0~0~0~0~0~7~3~ --00248c6a671acfdb9c04c558d753 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable @bill

notice the "= " which breaks the link. My regex produces:

 Array ( [0] => http://techcrunch.com/2012/07/20/kickstarter-flashr-wants-to-make-the-iphon= [1] => http://techcrunch.com/2012/07/2= [2] => http://techcrunch.com/2012= ) 

When I copy and paste the string and and run it though string replace then it replaces the "= "

Any idea what's going on?

Thanks

  • 写回答

1条回答 默认 最新

  • dousendun8411 2012-07-21 16:29
    关注

    The text is in an encoding called "Quoted Printable". Decode it first into normal text:

    http://php.net/manual/en/function.quoted-printable-decode.php

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

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动