假设要拆分$text是:
Question 1 - Parabolas
... /**/
Question 2 - Permutations
... /**/
Question 3 - Integration
如何分裂以获得分量计
"问题X-",其中X可以表示任何数字。通过:
$question = explode("Question X -", $text);
我绝对必须包括后面的破折号。
为此,您必须使用正则表达式。
例:
$text = "Question 1 - Parabolas";
preg_match('/Question [0-9]+ - (.*)/', $text, $matches);
echo $matches[1];
输出:
Parabolas
如果要使用多行执行此操作,则必须preg_match_all
然后循环遍历匹配项。问题将在索引 1 处!