Hello all,
I need to process a small part out of a big file.
I thought first to transform the file into an array using file()
after that I need to look for a specific string (it's a substring actually) in that file array that will indicate the location which the processing should begin.
in_array() is not helpful because as I mentoined it is a substring and in_array will return false and won't give the index as well.
maybe there is another way by reading it directly from the file but then I need to move the pointer top the specified location.
any ideas that can help me?
Thanks
move file pointer to specofic location
Moderator: General Moderators
If you have enough memory to put the whole file in a var use a full string instead of an array..
Code: Select all
<?php
$needle = 'my stuff';
$haystack = join('',file('filename'));
$startpos = strpos( $haystack, $needle ); // use stripos() for case insensitive
if ($startpos === false)
{
// It was not found
}
else
{
// it was found at $startpos
}
?>