2

Can I call a Classic ASP vbscript function and have it return html? I have a function that does some calculations, but I want it to send back the html as well. Will it do that? .

response.write MyFunction()
function myFunction()
  return "<b>test</b>"
end function

I get a type mismatch error.

Second question, please, If this were php, can I send back html and do something like echo MyPHPFunction()?

I didn't know if php was different than asp/vbscript on this. It seems you can send just about anything around in php.

Thank you.

johnny
  • 19,272
  • 52
  • 157
  • 259

3 Answers3

5

In vb script, assign the return value to the function name; something like this:

function myFunction()
    myFunction = "<b>test</b>"
end function
Romeo
  • 1,093
  • 11
  • 17
4

ASP:

<%
Function MyFunction()
  MyFunction = "<b>test</b>"
End Function

Response.Write MyFunction()
%>

PHP:

<?php
function MyPHPFunction() {
  return "<b>test</b>";
}

echo MyPHPFunction();
?>

ASP with a parameter:

<%
Function MyFunction2(inStr)
  MyFunction2 = "<b>" & Server.HTMLEncode(inStr) & "</b>"
End Function

Response.Write MyFunction2("foo & bar")
%>

PHP with a parameter:

<?php
function MyPHPFunction2($inStr) {
  return "<b>" . htmlentites($inStr). "</b>";
}

echo MyPHPFunction2("foo & bar");
?>
artlung
  • 33,305
  • 16
  • 69
  • 121
1

You could have

<?php    
function printHelloWorld(){
     echo 'hello world';
}
function getHelloWorld(){
     return 'hello world';
}

printHelloWorld();
//output: hello world
echo getHelloWorld();
//output: hello world
?>
Daniel
  • 1,321
  • 12
  • 25