[Solved] Function does not return value !

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phphi
Forum Newbie
Posts: 2
Joined: Fri Jun 01, 2012 4:21 am

[Solved] Function does not return value !

Post 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";
?>
Last edited by phphi on Fri Jun 01, 2012 8:41 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Function does not return value !

Post 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;
}
phphi
Forum Newbie
Posts: 2
Joined: Fri Jun 01, 2012 4:21 am

Re: Function does not return value !

Post by phphi »

Celauran wrote:You
I dont believe this...
I see your are right, I see the error
:banghead:
Post Reply