我正在尝试从字符串中获取数字,但我不断获取带有数字的完整字符串,而不是单独的数字
$string = "stuff here with id=485&other=123";
preg_match('(id=\d+)',$string,$match);
Run Code Online (Sandbox Code Playgroud)
上面的结果就像 id=485 但我只想要 485
任何帮助将不胜感激。
我的preg_match_all()功能有问题。我有一个字符串,例如
$string = '<div id="header">Hello</div>'
preg_match_all('/'.preg_quote('<div id="header">').'(.*?)'.preg_quote('</end>').'/s', $string, $matches);
Run Code Online (Sandbox Code Playgroud)
我正在寻找输出Hello。
但我只收到这个错误:
preg_match_all():第 13 行 C:\xampp\htdocs\classes\Functions.php 中的未知修饰符 'd'
我正在尝试使用preg_match,但我无法获得正确的模式.
字符串看起来像[abc] def [ghi] jul [mno]pqr.
我需要类似的东西array(abc => def, ghi => jul, mno => pqr).
有任何想法吗?
我正在解析一个<avg_cpc>some number</avg_cpc>有时候没有值的xml文件.
我的正则表达式看起来像这样:
<is_adult>(.*?)</is_adult>.*?<trademark_probability>(.*?)</trademark_probability>.*?<total_extensions_used>(.*?)</total_extensions_used> **here comes the <avg_cpc>some number</avg_cpc>** .*?</appraisal>
Run Code Online (Sandbox Code Playgroud)
如何使这个正则表达式匹配没有cpc值的项目?我没试过就试过了(<avg_cpc>.*?</avg_cpc>)?.谢谢 !
我试图使用该preg_match_all()函数从php中的字符串中提取电话号码.我知道这种模式会'!\d+!'提取所有数字.但我需要它做更多.我要提取的数字要么以256开头,后跟9个数字,要么是078,077,071,079,后跟8个数字.谢谢.