2012-08-05 3 views
-3

기본적으로 1.&nbsp에서 시작하여 <div의 첫 번째 문자로 끝나는 텍스트를 추출하는 데 bash 쉘 스크립트 cat new | sed '/1.&nbsp/,/<div/!d' > new2을 사용하고 있습니다. 그런 다음 new2 파일에 저장합니다. pcre를 사용하여 PHP에서 동일한 작업을 수행하는 방법.pcre에 대한 sed와 동일한 구문

답변

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 
관련 문제