Reputation: 19735
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
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
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
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