a function from VB to PHP[solved]
hi, can somebody convert the VB code below to php
VB Code:
Private Function Between(Begining As String, Ending As String, TextToLookIn As String) As String
Dim Be, En, TTLI As String
Be = Begining
En = Ending
TTLI = TextToLookIn
TTLI = Right(TTLI, Len(TTLI) - (InStr(1, TTLI, Be) + Len(Be) - 1))
Between = Left(TTLI, InStr(1, TTLI, En) - 1)
End Function
Re: a function from VB to PHP
Re: a function from VB to PHP
it returns the string value between "Beginning" and "Ending" variables, in the given text.
Re: a function from VB to PHP
So if I have a string:
PHP Code:
$str = 'This is a test string with some random words';
echo(Between('test', 'random', $str));
The ouput would be:
"string with some" ?
Re: a function from VB to PHP
yes
can you do it in PHP?
Re: a function from VB to PHP
Done:
PHP Code:
function between($start, $end, $string)
{
$pos1 = strpos($string, $start) + strlen($start);
$pos2 = strpos($string, $end) - 1;
return substr($string, $pos1, $pos2 - $pos1 + 1);
}
I'll let you decide its behviour if one or both the search strings are not found.
Re: a function from VB to PHP
wow thanks.
I'm kind of a newbie in PHP, can you explain the functions you used?
Re: a function from VB to PHP
Bill Gates killer, that is in PHP... just add the
<?
?>
tags to it...
Re: a function from VB to PHP
strpos = (VB) InStr - it returns the index (0 based) of the first occurence of the search string.
substr = (VB) Mid - which returns a portion of a stirng, given a start position and the length all be it more powerful than VB's Mid function. ;)
The strpos function returns false if it cannot find a string so to set that you would need to use if($pos1 === false).
Re: a function from VB to PHP
thanks VisualAd
Quote:
Originally Posted by thegreatone
Bill Gates killer, that is in PHP... just add the
<?
?>
tags to it...
what did you mean by that :confused: ? I know that's PHP.