سلام
این کدی که نوشتم مشکل شما رو حل می کنه :
اول فایل test.php
<html>
<head>
</head>
<body>
<span class=lm>
For Example
<div class=nx>
</body>
</html>
و این هم روش استخراج متن مورد نظر : (ویرایش شد)
<?php
$content = array();
$str="";
$pos;
$x = 0;
$tag = "<span class=lm>";
$tag2 = "<div class=nx>";
$file = fopen('test.php','r');
while(!feof($file)){
$line[] = fgets($file);
}
foreach($line as $val){
if(strstr($val,$tag)){
$pos = strpos($val,$tag);
$i = $pos + 15;
for($i; $i != strlen($val); $i++){
$str .= $val[$i];
}
$content[] = $str;
$x = 1;
}
if($x == 1){
if(!strstr($val,$tag2)){
$content[] = $val;
}else if(strstr($val,$tag2)){
$pos="";
$str="";
$pos = strpos($val,$tag2);
for($i=0; $i < $pos; $i++){
$str .= $val[$i];
}
$content[] = $str;
break;
}
}
}
foreach($content as $val){
echo $val;
}
موفق باشید