Page 1 of 1

[Solved] Function does not return value !

Posted: Fri Jun 01, 2012 4:28 am
by phphi
All the problem that seems to me is, that php does not return the variable. Variable r is correctly created,but not returned.

Code: Select all

#!/usr/bin/php
<?php error_reporting("E_ALL");
// Get part of string defined by starting and ending string
function getPartOfString($string,$startPos,$endPos){

//If no starting string do this
if($startPos==""){echo"test1\n";
	$p=explode($endPos,$string);	
	return$p[0];}

//If no ending string do this
if($endPos==""){echo"test2\n";
	$p=explode($startPos,$string);
	return$p[1];}

//If both present do this
if($endPos!="" and $startPos!=""){echo"test3\n";
	$p=explode($startPos,$string);
	$pp=explode($endPos,$p[1]);
	$r=$pp[0];
	echo"Value to return = $r\n";
	return$r;}
                                  }
//reorganise value order insertnion
function getPartOfString2($startPos,$endPos,$string){	getPartOfString($string,$startPos,$endPos);}

//execute command
// return string between gs and zb
echo">".getPartOfString2("gs","zb","549df852pgsf64875621szby8474zu584")."<\n";
?>

Re: Function does not return value !

Posted: Fri Jun 01, 2012 5:37 am
by Celauran
You haven't defined a return in the second function.

Code: Select all

function getPartOfString2($startPos,$endPos,$string)
{
    $return_value = getPartOfString($string,$startPos,$endPos);
    return $return_value;
}

Re: Function does not return value !

Posted: Fri Jun 01, 2012 8:38 pm
by phphi
Celauran wrote:You
I dont believe this...
I see your are right, I see the error
:banghead: