pphi Posted June 1, 2012 Share Posted June 1, 2012 Its suppose to return part of string. $r is not returned . . . It looks like an error in php <?php function l($v,$sp,$ep){ if($sp==""){echo"test1\n";$p=explode($ep,$v);return$p[0];} if($ep==""){echo"test2\n";$p=explode($sp,$v);return$p[1];} if($ep!="" and $sp!=""){echo"test3\n";$p=explode($sp,$v); $pp=explode($ep,$p[1]);$r=$pp[0]; echo"Value to return = $r\n";return$r;} } function p($sp,$ep,$v){ l($v,$sp,$ep);} echo">".p("gs","zb","549df852pgsf64875621szby8474zu584")."<\n"; ?> Link to comment https://forums.phpfreaks.com/topic/263472-function-does-not-return-value/ Share on other sites More sharing options...
jason310771 Posted June 1, 2012 Share Posted June 1, 2012 try adding a space after each of the 'return' s return $p[0]; return $p[1]; return $r; Link to comment https://forums.phpfreaks.com/topic/263472-function-does-not-return-value/#findComment-1350255 Share on other sites More sharing options...
BK201 Posted June 1, 2012 Share Posted June 1, 2012 You sure it's not returning $r or just not echoing; echo"Value to return = $r\n";return$r;} That echo's $r not the value of $r, unless you wanted it that way. Also, are you checking for an empty string.. or? In the if statements. Link to comment https://forums.phpfreaks.com/topic/263472-function-does-not-return-value/#findComment-1350267 Share on other sites More sharing options...
pphi Posted June 1, 2012 Author Share Posted June 1, 2012 I made it more visible. Looks like what you suggested doest not work. its weird. all is set as its suppose to. #!/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"; ?> Link to comment https://forums.phpfreaks.com/topic/263472-function-does-not-return-value/#findComment-1350413 Share on other sites More sharing options...
pphi Posted June 2, 2012 Author Share Posted June 2, 2012 [solved] Function 2 does not return value // edit I dont see solved button on the forum Link to comment https://forums.phpfreaks.com/topic/263472-function-does-not-return-value/#findComment-1350465 Share on other sites More sharing options...
Pikachu2000 Posted June 2, 2012 Share Posted June 2, 2012 It's below. Says "TOPIC SOLVED" . . . Link to comment https://forums.phpfreaks.com/topic/263472-function-does-not-return-value/#findComment-1350477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.