IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
PHP
Search PHP Group:

Advanced
-Collapse +Expand PHP Store
PRESTWOODSTORE

Prestwood eMagazine

December Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...PHPLanguage Ref...   Print This     
  From the October 2015 Issue of Prestwood eMag
 
PHP Language Reference:
PHP Custom Function (function)
 
Posted 16 years ago on 11/16/2008 and updated 1/29/2009
PHP Code Snippet:
 A flashcard from our PHP Flashcards Library
 A code snippet from our PHP Code Snippets Page

KB101635

Languages Focus: Custom Routines

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

PHP Custom Function

PHP uses functions and loosely typed parameters. Function definitions can come before or after their usage so my preference when mixing PHP in with a mostly HTML page is to put the functions after the </html> tag.

Syntax Example:
function sayHello($pName) {
 echo "Hello " . $pName . "<br>";
}
 
function add($p1, $p2) {
 return $p1 + $p2;
}

Complete Example

The following is a complete example of adding PHP to an HTML page. You can put PHP functions at the top or bottom of your HTML page but my preference is for the bottom as demonstrated below.

<html>
<head>
<title>PHP Custom Routines</title>
</head>
<body>
<?PHP
sayHello("Mike");
echo "2+3=" . add(2,3);
?>
</body>
</html>
<?PHP
function sayHello($pName) {
 echo "Hello " . $pName . "<br>";
}
function add($p1, $p2) {
 return $p1 + $p2;
}
?>

More Info


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P144A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101635 Counter
14206
Since 11/16/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]