-3

基本上我使用 bash shell 脚本来cat new | sed '/1.&nbsp/,/<div/!d' > new2提取从. 然后将其保存到一个 new2 文件中。如何使用 pcre 在 php 中做同样的工作。 1.&nbsp<div

4

1 回答 1

1
$text = file_get_contents('php://stdin');
$matches = array();
if(preg_match('/1\.&nbsp(.*?)<div/', $text, $matches)) {
  echo $matches[1];
}

测试:

echo 'abc 1.&nbsp;This is a test<div>more stuff<div>and more' | php test.php
;This is a test
于 2012-08-05T19:21:59.923 回答