dqpu4988 2017-04-05 23:23
浏览 12
已采纳

当响应处于多行或单行时,PHP列表功能

I use CURL method to post and receive response from the SMS aggregator.

$url = "https://www.smsgatewaycenter.com/library/send_sms_2.php?".$request;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);    
list ($status, $returnmobileno, $statusdetails) = split('\|', $curl_scraped_page);

Now my aggregator gives response in single when I send single SMS like this

 $curl_scraped_page = "success | 919********** | 659613958369444158-117942947553648183"; //THIS IS EXAMPLE 

So I use list function to get unique id 659613958369444158 before the hyphen. I am all good until I get a single response but when I get response as under, am not able to get the first unique id from the response.

Multiline Response

 success | 917*********| 3287615453600499019-106346209426268709 
 success | 919********* | 3287615453600499019-483762398162272572 
 success | 9196********** | 3287615453600499019-204615952244351373 

Or Single Line Multi Response

success | 917*********| 3287615453600499019-106346209426268709 success | 919********* | 3287615453600499019-483762398162272572 success | 9196********** | 3287615453600499019-204615952244351373 

From above given multi-line or single line multi response. I just need to catch success/error and 3287615453600499019 and store it in my DB.

Somehow lost it even with preg_match().

How should I be able to achieve it?, I finally gave up after trying for 3 hours and seeking help here.

  • 写回答

1条回答 默认 最新

  • drl47263 2017-04-05 23:32
    关注

    /(\d+)-/ should work just fine to put the desired number into a capture group:

    <?php
    $str = "success | 917*********| 3287615453600499019-106346209426268709 success | 919********* | 3287615453600499019-483762398162272572 success | ";
    if (preg_match("/(success|error) \|.*?\| (\d+)-(\d+)/", $str, $matches)) {
        echo "$matches[1] - $matches[2]";
    } else {
        // no match
    }
    

    Output:

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图