johnny
johnny

Reputation: 19735

Can I return html from a classic asp vbscript asp function? What about PHP?

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.

Upvotes: 2

Views: 2494

Answers (3)

artlung
artlung

Reputation: 33813

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");
?>

Upvotes: 4

Daniel
Daniel

Reputation: 1341

You could have

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

printHelloWorld();
//output: hello world
echo getHelloWorld();
//output: hello world
?>

Upvotes: 1

Romeo
Romeo

Reputation: 1093

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

function myFunction()
    myFunction = "<b>test</b>"
end function

Upvotes: 5

Related Questions