-2
<?php 
    function A() {
        return "<?php echo \"some text\"; ?>";
    }
    echo A();
?>

I expected to see "some text" on the page, but i did not. So how do I make this code work? Thanks in advance.

UPD: I'm sorry for the not clear description. I'm going to insert a random number into the value of the input.

<?php 
 function print_form() {
    return "<form method=\"POST\">
    <input type=\"text\" name=\"code1\" value=\" <?php echo rand(0, 999999); ?> \" />
    </form>"; 
 }
    echo print_form(); ?>

3 Answers3

1

mate you have to return the text not a PHP code:

<?php 
    function A() {
        return "some text";
    }
    echo A();
?>
Sofiane Sadi
  • 357
  • 1
  • 7
  • this is not the answer according to the question. he wants to run the code inside the function and return the output. not just output the string. – itachi Mar 16 '15 at 17:04
  • 1
    @itachi Not really: `I expected to see "some text" on the page` – jeroen Mar 16 '15 at 17:12
1

Concatenate the return of the function:

return "<form method=\"POST\">
<input type=\"text\" name=\"code1\" value=\"" . rand(0, 999999) . "\" />
</form>";
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
-1
<?php 
 function print_form() {
    return '<form method="POST">
    <input type="text" name="code1" value="'.rand(0, 999999).'" />
    </form>'; 
 }
    echo print_form(); ?>

you are returning, so just concatenent the value.

itachi
  • 6,323
  • 3
  • 30
  • 40