Use functions instead of require operations in php_PHP tutorial

WBOY
Release: 2016-07-20 11:17:32
Original
842 people have browsed it

In order to reduce repeated code, it is often necessary to include header and footer. The most commonly used operations are require or require_once and other codes, but we can use another way to achieve this inclusion, write a function, For example, printHeader, as shown below, seems to be more troublesome to turn one line of code into two lines, but it can achieve some additional effects. For example, if we want each page to have a different title, we can pass parameters to this function (as shown below) Show).

function printHeader($title)
{
    require("../lib/header.php");
}
Copy after login

Also in header.php

<html>
    <head>
        <title><?= $title ?></title>
...
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371984.htmlTechArticleIn order to reduce repeated code, it is often necessary to include header and footer. The most common operations we use are require or require_once, etc. code, but we can do it in another way...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template