Dubz
07-20-2012, 06:24 AM
A guy I know made a script that had these functions in it. They appear to do the same job, but my question is, whats the difference (besides that it uses different sub-functions)?
function strbet($inputstr, $deliLeft, $deliRight)
{
$posLeft = strpos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = strpos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
function stribet($inputstr, $deliLeft, $deliRight)
{
$posLeft = stripos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = stripos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
I tested it out with this code and it came out with the same results:
<?php
$alphabet = 'abcdefghijklmnopqrstuvwxyz';
$data = strbet($alphabet, 'h', 'q');
$data2 = stribet($alphabet, 'h', 'q');
echo $data."<br />\n".$data2;
function strbet($inputstr, $deliLeft, $deliRight)
{
$posLeft = strpos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = strpos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
function stribet($inputstr, $deliLeft, $deliRight)
{
$posLeft = stripos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = stripos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
?>
I guess the guy just made the function two ways, I don't know why but its not a big deal and I'll probably ask him why later.
function strbet($inputstr, $deliLeft, $deliRight)
{
$posLeft = strpos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = strpos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
function stribet($inputstr, $deliLeft, $deliRight)
{
$posLeft = stripos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = stripos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
I tested it out with this code and it came out with the same results:
<?php
$alphabet = 'abcdefghijklmnopqrstuvwxyz';
$data = strbet($alphabet, 'h', 'q');
$data2 = stribet($alphabet, 'h', 'q');
echo $data."<br />\n".$data2;
function strbet($inputstr, $deliLeft, $deliRight)
{
$posLeft = strpos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = strpos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
function stribet($inputstr, $deliLeft, $deliRight)
{
$posLeft = stripos($inputstr, $deliLeft) + strlen($deliLeft);
$posRight = stripos($inputstr, $deliRight, $posLeft);
return substr($inputstr, $posLeft, $posRight - $posLeft);
}
?>
I guess the guy just made the function two ways, I don't know why but its not a big deal and I'll probably ask him why later.