A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[Release - PHP] Streamlined GetStringBetween and GetAllStringBetween

1k views · started by Chris ·
#1
[Release - PHP] Streamlined GetStringBetween and GetAllStringBetween
<?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
#2
I.

Needed.

This.

Thanks