1

In the following code the variable does not seem to be getting set. Seems simple enough but for some reason this is vexing me.

function teasertext($string){
    $tstring = "";
    if (strlen($string)>9){
        $tstring .= substr($string,0,9) . "....";
    }
    else
    {
        $tstring .= $string;
    }
}
print $tstring;
return $tstring;
1
  • Rule #1, always indent consistently. It will show you why some things don't work (in your case, the print and return statements are outside of the function block)... Commented Aug 23, 2010 at 16:16

2 Answers 2

2
print $tstring;
return $tstring;

is outside of the function block.

function teasertext($string){
    $tstring = "";
    if (strlen($string)>9){
        $tstring .= substr($string,0,9) . "....";
    }
    else
    {
        $tstring .= $string;
    }
    print $tstring;
    return $tstring;
}

Should return $tstring properly.

Sign up to request clarification or add additional context in comments.

Comments

-1

I placed the variables outside of the function. Silly mistake.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.