-1

即我有一个字符串,其中包含任何、任何类型的符号、单词、句子:

<START>%6tge9ruj+_]`\Qe,3[][}~[wq]we-Oke|\;'"_p}|P{dl3=+fmwfoe-f <END>

如何:

1) get everything between <start> and <end>

2) replace everything <start> and <end>

谢谢回答!

4

1 回答 1

1

使用正则表达式提取标签之间的部分:

<?php

$text = '<START>%6tgruj+_]`\\Qe,3][}~[e-Oke|;\'"=+fmwfoe-aaa<END>aaaa<END>';
$pattern = '/<START>(.*?)<END>/';   //<-------- till the first occurence of <END>
$pattern = '/<START>(.*)<END>/';    //<-------- till the last occurence of <END>
$out = array();

preg_match($pattern, $text, $out);      var_dump($out);
?>

演示。但这真的不是正则表达式的工作,你应该考虑使用一些解析器。

于 2013-02-07T18:47:37.467 回答