-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