I have a file and I want to echo the text from character 2 to 27. How can I do this?
Thanks
Thanks
<?php
$break = "\n";
$textfile = "cake";
$file = fopen("$textfile", 'r');
$data = fread($file, filesize($textfile));
fclose($file);
$start = strpos($data, $_GET["email"]);
$end = strpos($data, $break, $start );
echo substr($data, $start, $end);
?>
<?php
$break = "\n"; //set the line break character
$textfile = "cake"; //set the file we want to read
$file = fopen("$textfile", 'r'); // open the file in read mode
$data = fread($file, filesize($textfile)); // read the whole file and save it in a variable
fclose($file); //close the file
$start = strpos($data, $_GET["email"]); //find the first character's position of the string given in the url
$end = strpos($data, $break, $start ); //find the position of the last character in the line
$end1 = $end - $start; //subtract the end character from the start character to find the string lenght and save it in a variable
echo substr($data, $start, $end1); //use substr to trim the file contents and provide it with the file content, the starting character and the lenght and echo the part/line we want
?>
Comment