1

When I call a function mainfunc() I want to put an explicit value near to the output of a function as a parameter of mainfunc(). I want to do someting like mainfunc('foo'.LaTeX());.

But, when I do that, I get the output of LaTeX() before “foo”, it exactly print me LaTeXfoo (the output of LaTeX() is LaTeX) and I got the same thing when I try to permute it like LaTeX() . foo.

So, this is the deffinition of the function LaTeX() :

function LaTeX()
{
    ?><span class="latex">L<spu>a</sup>T<sub>e</sub>X</span><?php
}

So, what can I do to make mainfunc exactly receive fooLaTeX by using LaTeX() function, please?

3
  • This should be moved to tex.stackexchange.com or StackOverflow. Commented Jul 27, 2014 at 11:47
  • in Latex() function use return instead of printing! Commented Jul 27, 2014 at 12:00
  • StackOverflow, sure. But tex no, because it is a question about PHP, I use a PHP command to print the name of LaTeX correctly formatted but it could be another function. Commented Jul 27, 2014 at 15:18

1 Answer 1

2

The answer is simple:

Don't print (which is what happens if you close the PHP code and reopen).

The following two lines of code will essentially do the same thing (they're equivalent):

echo '<b>Hello World!</b>';

?><b>Hello World!</b><?php

Instead, work with return values:

function LaTeX()
{
    return '<span class="latex">L<sup>a</sup>T<sub>e</sub>X</span>';
}

This will create the behavior you're looking for. However, if you just plan on returning a fixed string, better define a constant:

define(LaTeX, '<span class="latex">L<sup>a</sup>T<sub>e</sub>X</span>');

mainfunc('foo' . LaTeX);
Sign up to request clarification or add additional context in comments.

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.