I have a TXT file that contains several different records, in some cases I need to get the information that is between 2 strings, eg Cliente: FULANO DE TAL CPF:
I need it to be between Cliente: e CPF:
.
In other parts of the same document I need to get the first 12 characters of a line after the string Tipo_OS:
if there is any information after the Tipo_OS:
and before another string also fixed in the document, since there may or may not be data between these strings.
Note that I do not have a standard separator character to generate my arrays, I could use :
, however some data is not after :
but in the line below or even after other data in the line below.
I know it sounds kind of confusing, but what I already got was the following: I found a function on the internet that allows me to get values between 2 strings.
function GetBetween($var1="",$var2="",$pool){
$temp1 = strpos($pool,$var1)+strlen($var1);
$result = substr($pool,$temp1,strlen($pool));
$dd=strpos($result,$var2);
if($dd == 0){
$dd = strlen($result);
}
return substr($result,0,$dd);
}
Even though it is functional, however, in echo
, the other data in the document still appears, excluding only the string that I set as the initial and final string.
Initially what I need would be the following, find a value between 2 strings and only display it, however I want to define several values between 2 strings until I capture all the information of this service order, after I capture everything I need to run a while
to check if there are more things on the next pages, thus mounting my database with the service orders contained in that document. Every time the document reads Cliente:
it identifies that it is the beginning of a new record.