php - 如何在 [ ] 之间获取字符串
问题描述
$input="[youtube id=HmV4gXIkP6k]";
preg_match_all("~[(.+?)]~",$input,$output);
var_dump($output);
如何在[]中获取字符串?
解决方案
您也可以不使用正则表达式:
$Index1 = strpos($input, '[');
$Index2 = strpos($input, ']');
$Result = substr($input, $Index1+1, $Index2-$Index1-1);
推荐阅读
- swift - WKWebview - 加载资源失败:请求超时
- flutter - 在颤振中生成要点
- java - 创建 com.luv2code.springsecurity.demo.config.DemoAppConfig 中定义的名称为“viewResolver”的 bean 时出错
- python - 使用python从网站上抓取广告网址
- android - 无法在 Android 上配置地理位置 API KEY
- apache-zookeeper - Apache Curator 无法重置过期会话(Apache Curator 4.2.0;Apache Zookeeper 3.4.0)
- bootstrap-4 - 为什么我不能垂直对齐引导列中的元素?
- xpath - 使用 xpath 更改 menuitem 操作或继承
- c - 由于代码错误,未检测到 StackSmashing
- python - google_play_scraper 输出到 csv