0

大家好,我有一个问题,

假设有人放"Hi lets have #fun and than more #fun"现在假设我想获取第二个标签,包括与之相连的单词并将其存储到变量中。

我将如何获得第二部分,因为 using(strpos($a,'#fun')只会返回第一部分。

感谢您的时间!

大卫

编辑:

这是我所做的:

$code = "Hi lets have #funfgs and than more #funny";
$pos1 = strpos($code, '#');
$pos2 = strpos($code, '#', $pos1 + strlen('#'));
echo substr($code, $pos2);
4

1 回答 1

1

您可以使用以下正则表达式

$code = "Hi lets have #fun and than more #fun";

$pattern = "$#[^\s]*$i";

preg_match_all($pattern, $code, $matches);

print_r($matches);
于 2013-03-22T04:35:50.417 回答