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 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据