我试图在$something
和$something_else
之间找到一个文本,并将其丢弃在数组中。我认为你需要preg_match
来做这件事,但我已经尝试了很多,但仍然不知道。
无论$something
和$something_else
是什么,这都应该有效。
您需要阅读preg_match
和preg_match_all
的文档。
下面是一个简单的例子,它将匹配里面的任何内容(双引号)。。
<?php
preg_match_all('~"(.*?)"~',
'Hey there "I will be matched", because "I am inside the double quotes"',
$out, PREG_PATTERN_ORDER);
print_r(($out[0]));
输出:
Array
(
[0] => "I will be matched"
[1] => "I am inside the double quotes"
)
如果我错了,请纠正我。我们可以使用将一个字符串分解成一个数组。对数组中每个单词的另一个字符串使用pre_match_all。通过这种方式,它可以处理任何字符串。