note 52794 added to ref.funchand
| From: | MichaelT dot McGrew at osu1 dot php dot net | Date: | Thu, 12 May 2005 16:56:55 +0000 |
| Subject: | note 52794 added to ref.funchand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89342@lists.php.net to get a copy of this message | ||
An interesting way to use functions is by putting other things than PHP in them, i.e. HTML CSS. This
can be useful if you will be using a format for many pages. Yes, the include function can be used
also, but by defining them in functions can make them more portable in a way and keep you from
having to make many include files. You could use include() when one will be putting big portions of
PHP, HTML, and/or CSS and will be using them in many pages. Then you could use PHP, HTML, and/or CSS
in a function when it is smaller portions of code and only want it to be on a few pages.
I have been using include() for HTML and CSS in my early days of PHP coding, but I will be using
functions for that a lot more now.
<?php function a() { ?>
<style type="text/css">
table {
border: 1px dashed black;
background: #95EAFE;
text-align:left;
width:610px;
}
.linkbar {
font-family:sans-serif;
line-height:40px;
top:1px;
text-align:center;
width:200px;
height:10px;
}
</style>
<?php } ?>
Now doing:
<?php a(); ?>
will return all of the CSS just as if you had wrote it on the actual page, or used include() . The
same thing goes for HTML code inside a function. The possibilities are endless...
----
Manual Page -- http://www.php.net/manual/en/ref.funchand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52794
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52794&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52794&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52794&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52794&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52794&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52794&report=yes
Search -- http://master.php.net/manage/user-notes.php