...

View Full Version : getting file contents from within delimiters



DesignersToolz
04-04-2004, 03:21 AM
How would I go about getting file contents between delimiters?


Example:

$delimiter_number = "3";



file "foo.txt" contains:

fgfdgf
gf

gf
gfgdsfgfdgdsfgfdgdsgfdgfd

<!-- start$delimiter_number -->
Random text
<!-- end$delimiter_number -->

fgfdgsfdg464




How would I snag "Random text" from within the delimters?

boeing747fp
04-04-2004, 03:27 AM
are u trying to get it off from another page or the same page?

DesignersToolz
04-04-2004, 03:32 AM
I said its coming from a file.

boeing747fp
04-04-2004, 03:40 AM
maybe something like this base code by www.mikenew.net
---------------------------

<?php
$thefile = "FILENAME HERE";
$fd = fopen($thefile, "r");
$value = "";
while(!feof($fd)){
$value .= fread($fd, 4096);
}
fclose($fd);

$startingpoint = "<!-- start$delimiter_number -->";
$endingpoint = "<!-- end$delimiter_number -->";

$value = "";

$start= strpos($value, "$startingpoint");
$finish= strpos($value, "$endingpoint");
$length= $finish-$start;
$value=substr($value, $start, $length);

$echo = preg_replace("/(href=\"?)(\/[^\"\/]+)/", "\\1" . $thefile . "\\2", $value);
echo $echo;
flush ();
?>

sidney
04-06-2004, 01:19 PM
<?php
$txt = file_get_contents('http://www.example.com/');
$delimiter_number = "3";
$one=explode("<!-- start".$delimiter_number." -->",$txt);
$two=explode("<!-- end".$delimiter_number." -->",$one[1]);
$bit=$two[0];
echo $bit;
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum