php - 在变量中获取值之后的所有内容
问题描述
在$contents
,我想在管道之后抓住所有东西,例如boss
。
$search_for = "micky.mcgurk";
$contents = "micky.mcgurk@somewebsite.com|boss";
$pattern = sprintf('/\b%s@([^|\s]+)\|/m', preg_quote($search_for));
if (preg_match_all($pattern, $contents, $matches)) {
$submitted_by = implode("\n", $matches[1]);
} else {
echo "No user found";
}
解决方案
$resultat = substr(strrchr($content, '|'), 1);
推荐阅读
- android - Android adb 在 macOS Catalina 上看不到 android 设备
- javascript - 如何设置允许用户在 React.js 中选择的最大日期
- python - struct.pack 和 encode 是否产生相同的字节串?Python
- android - Google Play Closed Test Track URL 不适用于任何人
- flutter - 为什么应用程序第一次运行时,Flutter 中的 BottomNavigationBar 和 TabBar 为空白?
- python - 在这种情况下,我怎样才能最好地解决函数比较 TypeError ?
- python - 是否可以在运行 Jupiter 笔记本时将日志级别设置为 DEBUG?
- javascript - 为 href 链接使用下拉值
- pandas - Pandas 中 Groupby 的索引范围
- latency - 如何计算硬盘的延迟时间?