themoose
February 23rd, 2006, 12:48
I'm trying to get a script to read each line of a file, get the text between the <b> tags and echo it. So far I've got this but it doesnt really work:
<?php
function getBetween($str, $start, $end) {
$startlen = strlen($start);
if (($startpos = strpos($str, $start)) !== false
&& ($endpos = strpos($str, $end)) !== false
&& ($skip = $startpos + $startlen) <= $endpos) {
return substr($str, $skip, $endpos - $skip);
} else {
return false;
}
}
$lines = file("file.html");
$start = "<b>";
$end = "</b>";
foreach($lines as $line) {
if(($echo = getBetween($line, $start, $end)) !== false) {
echo $echo;
} else {
echo "Not Found";
}
}
?>
(I do not take credit for all of this code. I found most of it googling :))
It keeps on echoing Not Found, whatever I do. Please can somebody help me?
Thanks,
tm
<?php
function getBetween($str, $start, $end) {
$startlen = strlen($start);
if (($startpos = strpos($str, $start)) !== false
&& ($endpos = strpos($str, $end)) !== false
&& ($skip = $startpos + $startlen) <= $endpos) {
return substr($str, $skip, $endpos - $skip);
} else {
return false;
}
}
$lines = file("file.html");
$start = "<b>";
$end = "</b>";
foreach($lines as $line) {
if(($echo = getBetween($line, $start, $end)) !== false) {
echo $echo;
} else {
echo "Not Found";
}
}
?>
(I do not take credit for all of this code. I found most of it googling :))
It keeps on echoing Not Found, whatever I do. Please can somebody help me?
Thanks,
tm