dongmu2517 2017-04-23 08:39
浏览 10
已采纳

来自文本的Regexp PayPal交易ID

I run a website that accepts PayPal payments. When users have questions regarding their purchase they will send me their transaction ID through a self-coded ticket system.

I would like to turn the transactions IDs into URLs (to a link that will pull up transaction info) to make everything faster for me.

I know transaction IDs are 17 characters long. How would I go about this?

UPDATE:

When users post let us say. "Hi there, my name is John Doe. I made a purchase and I'm having issues with it. Transaction ID: XXXXXX". I need to be able to turn the XXXX into a link that pulls up transaction info. I can't figure out how to create this in PHP with preg_replace, so it only formats the transaction ID into the link.

I have the link that is needed to lookup the transaction info, but I just do not know how to use regex to find the transaction ID and then wrap a link around it.

  • 写回答

2条回答 默认 最新

  • dontoften8899 2017-04-23 09:32
    关注

    You might go for:

    \b[\dA-Z]{17}\b
    

    Which looks for a character string of length 17 with borders on both sides. If you know, it has only digits, this might be as well ~\b\d{17}\b~ but you did not elaborate on the specifications, really.


    In PHP this would be:
    <?php
    
    $string = <<<DATA
    When users post let us say. "Hi there, my name is John Doe. I made a purchase and I'm having issues with it. Transaction ID: XXXXXXXXXXXXXXXXX". I need to be able to turn the XXXX into a link that pulls up transaction info. I can't figure out how to create this in PHP with preg_replace, so it only formats the transaction ID into the link.
    
    I have the link that is needed to lookup the transaction info, but I just do not know how to use regex to find the transaction ID and then wrap a link around it.
    DATA;
    
    $regex = '~\b[\dA-Z]{17}\b~';
    
    $string_with_links = preg_replace($regex, "http://www.exaple.com/id/$0", $string);
    echo $string_with_links;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集