-3

basically I am using bash shell script cat new | sed '/1.&nbsp/,/<div/!d' > new2 to extract text starting from 1.&nbsp and ending at first occurrence of <div. And then saving it into a new2 file. How to do the same work in php using pcre.

Ananda
  • 1,572
  • 7
  • 27
  • 54

1 Answers1

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

Test:

echo 'abc 1.&nbsp;This is a test<div>more stuff<div>and more' | php test.php
;This is a test
Gary G
  • 5,692
  • 2
  • 27
  • 18