douna4762 2016-04-08 16:08
浏览 258

PHP - 带双引号字符串的正则表达式

I'm trying to use regular expressions to extract a certain value from a string:

"exec_hash": "/TPPE2ChB+5HuSHs84FBgx5/EgWi0OlaEXoXq4pq3Aukhc1Ypf0mZfKCJ10w=", "events_collector": "thiiM0ahsieSiech1phithe6chahngoo8sah6aid "

The data I want is the hash between the quotation marks. The problem is that there are multiple quotes within the string and preg_match_all function isn't returning the correct data. I've been playing around with regex for a while but can't figure it out. Ultimately, I'd like that data to be returned into a value. Ex: $string1 = '/TPPE2ChB+5HuSHs84FBgx5/EgWi0OlaEXoXq4pq3Aukhc1Ypf0mZfKCJ10w=';

Correction: I'm using curl to grab the page content. The data isn't stored in a variable.

$matches = array(); $thing = preg_match_all('/hash": "(.*?)", "events/',$page,$matches); print_r($matches);

It spits out a long array of much more than just the hash

  • 写回答

3条回答 默认 最新

  • dongsonglian7303 2016-04-08 16:16
    关注

    Can you use substr?

    haven't tested this, but in theory...

    $pos_of_comma = strpos($str, ",");
    if($pos_of_comma !== false) {
        $execHash = substr($str, 14, $pos_of_comma - 14);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?