DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Use The Current Filename As The HTML Body Id

  • submit to reddit
        // Makes the body id = the current filename - extension
// Useful while working on static markup that relies on styles/scripts targeting the current page 

	$page = $_SERVER['PHP_SELF'];
	$page = str_replace("/","",$page);
	$page = str_replace(".php","",$page);

<body id="<?php echo $page ?>">


Snippets Manager replied on Tue, 2008/06/10 - 3:11pm

True, that's better -- thanks :)

Snippets Manager replied on Sun, 2008/06/15 - 12:38pm

If i have a page att a url something like this script would output would not something like <?php $page = basename($_SERVER['PHP_SELF'], ".php"); ?> be better ? do you want the extra "testmypage" in the id from the directory path ?