Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用冒号(:)和分隔符(<;br>;)拆分句子_Php_Regex - Fatal编程技术网

Php 使用冒号(:)和分隔符(<;br>;)拆分句子

Php 使用冒号(:)和分隔符(<;br>;)拆分句子,php,regex,Php,Regex,输入 <?php $input = 'After <span style="color:green;">10</span> years : XYZ 38.38 <br><span style="font-size:11px;"><strong>AB212</strong> is applicable on 2025</span>'; ?> $Output[0

输入

<?php
$input = 'After <span style="color:green;">10</span> years : XYZ 38.38 <br><span style="font-size:11px;"><strong>AB212</strong> is applicable on 2025</span>';
?>
 $Output[0] = 'After <span style="color:green;">10</span> years';
 $Output[1] = 'XYZ 38.38';
 $Output[2] = '<span style="font-size:11px;"><strong>AB212</strong> is applicable on 2025</span>';

要将字符串拆分为由一个空格包围的冒号和可能由一个空格包围的标记,可以使用以下表达式:

/\s:\s |\s?
\s?/g

在这个表达式中,字符串中有一个
|
字符,表示要匹配它的左侧和右侧(即
\s:\s
\s?
\s?
)。从技术上讲,它充当逻辑

注意正则表达式末尾的全局修饰符的用法

你可以得到更多的信息

使用您的代码,它将是:

$output = preg_split('/\s:\s|\s?<br>\s?/g', $input)

您的预期输出包含php代码???您真的需要标签吗?您希望从输入中提取哪些变量?您的预期输出是什么?$output=preg_split('/:|
?/',$input);
$output = preg_split('/\s:\s|\s?<br>\s?/g', $input)
After <span style="color:green;">10</span> years
XYZ 38.38
<span style="font-size:11px;"><strong>AB212</strong> is applicable on 2025</span>