[Release - PHP] Streamlined GetStringBetween and GetAllStringBetween
PHP Code:
<?php
function GetAllStringsBetween ( $String , $Start , $End )
{
$Return = Array ( );
$Result = 0;
$LResult = 0;
while ( ( $Result = GetOffsetBetween ( $String , $Start , $End , $Result ) ) != -1 )
{
$Return[] = GetOffsetBetween ( $String , $Start , $End , $LResult );
$LResult = $Result;
}
return $Return;
}
function GetStringBetween ( $String , $Start , $End , $Offset = 0 )
{
if ( $Offset < strlen ( $String ) )
{
$StartPos = strpos ( $String , $Start , $Offset );
if ( $StartPos > -1 )
{
$EndPos = ( strpos ( $String , $End , ( $StartPos + 1 ) ) - 1 );
if ( $EndPos > -1 )
{
return substr ( $String , ( $StartPos + 1 ) , ( $EndPos - $StartPos ) );
}
}
}
return null;
}
function GetOffsetBetween ( $String , $Start , $End , $Offset = 0 )
{
if ( $Offset < strlen ( $String ) )
{
$StartPos = strpos ( $String , $Start , $Offset );
if ( $StartPos > -1 )
{
$EndPos = ( strpos ( $String , $End , ( $StartPos + 1 ) ) - 1 );
if ( $EndPos > -1 )
{
return $EndPos;
}
}
}
return -1;
}
?>
Requested by HTML ;P