Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

A PHP Tip for Site Developers; Hiding a Section of a Web Page

This tip is intended to make things a bit easier for you, a bit faster, and a lot less stressful. It's really handy.

An entire section of a web page, of any size, can be hidden from the browser (and from source code viewers).

Of course, being a PHP tip, it can be applied only to PHP web pages.

PHP code on a web page runs before the browser receives the page. (Unlike JavaScript, which runs after the browser receives the page.) Therefore, the effect of this tip occurs before the browser ever sees the content.

Use this tip instead of commenting out a section of the web page with an HTML comment tag. Here are 3 reasons:

  1. HTML comments can be seen when the web page source code is viewed.

  2. Sections of a web page removed with an HTML comment tag that itself contains HTML comments can be become a confused mess. HTML comments don't nest within HTML comments, so the inner comment tags need to be disabled.

  3. Using PHP to hide a web page section removes the section before it's sent to the browser. The section isn't there when the browser is used to view the source code.

Here's the code:

Immediately before the section to be hidden, insert this PHP code:

<?php if(false): ?>

Immediately after the section to be hidden, insert this PHP code:

<?php endif; ?>

The entire section between the two PHP items will be removed from the page. (The colon character [":"] in the first PHP item and the semi-colon character [";"] in the second PHP item are supposed to be that way.)

To temporarily (or permanently) display the content between the two PHP items, change if(false) to if(true) in the first PHP item.

You see how easy it is to switch back and forth, hiding and displaying a web page section, during development and testing.

I hope this tip is useful for you. We use it a lot. Not only for development, but also to hide comments within web pages so we don't need to keep a separate file of notes.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC