0

I'm calling a function that prints an output using "echo". for example:

function a(){
   echo 'example output';
}

problem is I don't have any control over this function and can't edit it. but I need to store the function's output to a variable like so:

$myVar = a();
// $myVar should now be 'example output'

I need to prevent the function from printing anything to the screen but I need it's output in $myVar.

is there anyway to achieve this?

3
  • 1
    change echo example output to return example output Commented Jan 23, 2020 at 11:41
  • I specifically mentioned I can't edit the function. that's the whole issue about it. Commented Jan 23, 2020 at 11:58
  • Can you speak to the person who does control it and ask them to improve it? (Or if it's just some code you downloaded and included in your script, there's actually nothing to stop you changing it really). Commented Jan 23, 2020 at 12:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.