-3
基本上我使用bash shell脚本cat new | sed '/1. /,/<div/!d' > new2
来提取文本从1. 
开始,并在第一次出现<div
结束。然后将其保存到new2文件中。如何在php中使用pcre做同样的工作。sed等效语法为pcre
基本上我使用bash shell脚本cat new | sed '/1. /,/<div/!d' > new2
来提取文本从1. 
开始,并在第一次出现<div
结束。然后将其保存到new2文件中。如何在php中使用pcre做同样的工作。sed等效语法为pcre
$text = file_get_contents('php://stdin');
$matches = array();
if(preg_match('/1\. (.*?)<div/', $text, $matches)) {
echo $matches[1];
}
测试:
echo 'abc 1. This is a test<div>more stuff<div>and more' | php test.php
;This is a test