我有一个HTML文件,它只包含文本。没有样式或任何东西。
文本如下所示:
ID NAME ANOTHER-ID-11-LETTERS MAJOR
例:
20 Paul Mark Zedd 10203040506 Software Engineering
ID
和ANOTHER-ID-11-LETTER
是数字。 NAME
MAJOR
是普通文本,也包含空格。
如何使用 PHP 去除它们并使每个单词或每个内容换行?
预期成果:
20
Paul Mark Zedd
10203040506
Software Engineering
看起来第一项总是一个数字,后跟一个空格,后跟一个可以是任何东西的名称,后跟一个数字,该数字是 11 位数字,后面还有一些文本。
您可以使用正则表达式和上述详细信息来拆分字符串
$test = preg_match("/([0-9]*?)'s(.*?)([0-9]{11})'s(.*)/is", "20 Paul Mark Zedd 10203040506 Software Engineering",$matchs);
print_r($matchs)
输出:
Array
(
[0] => 20 Paul Mark Zedd 10203040506 Software Engineering
[1] => 20
[2] => Paul Mark Zedd
[3] => 10203040506
[4] => Software Engineering
)
只需使用
preg_match:
#(['d]*)'s([a-zA-Z's]*)'s(['d]*)'s([a-zA-Z's]*)#
示例输出:
array (
0 => '20 Paul Mark Zedd 10203040506 SoftwareEngineering',
1 => '20',
2 => 'Paul Mark Zedd',
3 => '10203040506',
4 => 'SoftwareEngineering',
)