Jump to content

Function does not return value !


pphi

Recommended Posts

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

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";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.