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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.