Zend - The PHP Company




HTML

Add Code


0 An automatic title creator  

Type: application
Added by: fletcher
Entered: 21/11/2001
Last modified: 04/12/2008
Rating: - (fewer than 3 votes)
Views: 8175
Similar to a breadcrumbs script, it automatically completes the <title> field using directory and filename information


<?php
##################################################
##                                              ##
##              title.php v1.0                  ##
##              Copyright 2001                  ##
##                                              ##
##       Jim Fletcher jim@websitecode.com       ##
##                                              ##
##  Free to distribute as long as this notice   ##
##  remains. You cannot charge for this work or ##
##  any derivatives thereof. No warranties on   ##
##  this program are made or implied.           ##
##                                              ##
##################################################
## Revisions:                                   ##
## 1.0                                          ##
##                                              ##
## You may make any modifications to this script##
## to best fit your needs, but if you find some-##
## thing wrong, let me know at                  ##
##            jim@websitecode.com               ##
##################################################
#
# To run this script you will need PHP enabled on
# your server, and the PHP call:
#    include("/path-to-this-script/title.php");
# inserted within the <title></title> of the PHP 
#  pages you want it to run on.
#
# NOTE: the "/path-to-this-script/" listed above
# means change it to the location on YOUR
# webserver or delete it if the path.php is in the
# same directory as the calling page.
#
####################################
#          USER VARIABLES          #
####################################
#What is the path that is going to be parsed? You may pass comment this out and pass the $originalpath as a variable from the calling page, but in testing the $PHP_SELF variable came from the original calling page, not the path.php page.
$originalpath $PHP_SELF;

#What is the Base URL? (usually the domain name)
$urlbase "http://".$HTTP_HOST;
#$urlbase = "http://www.websitecode.com"; # Uncomment if the above line isn't working for you.

# What Link Text Do You Want To Appear for the link to the base URL?
$roottitle "Home";

# What file do you want to not print a link to? (drop the .php suffix & capitalize the filename)
$ignore = array("Index","Home","Default");

#######################################
# Do not modify beneath this point unless you know what you're doing!

function check_ignore($ignore,$referer){
  if (
count($ignore)){
    global 
$errors;
    
$found true;
    
#$referer = $path[$number];
    
for ($x=0$x count($ignore); $x++){
      if (
$ignore[$x] == $referer){
        
$found false;
      }
    }
    return 
$found;
  } else {
    return 
true//Not a good idea, if empty, it will allow it.
  
}
}


#Splits the path into an array using a forward slash
$path explode ("/"$originalpath);
#Counts How many elements are in the array so the loop below knows how long to loop
$totalelements count ($path);

# Loops thru the array formatting each element
    
for($number=1$number<$totalelements $number++) {
        
#Appends the next directory or file down to the URL
        
$urlbase $urlbase "/" $path[$number];
        
# Do Some Formatting on the Link Text
            #Replace Triple Underscore with Ampersand Surrounded By Underscores to be later converted to spaces
            
$path[$number] = str_replace("___""_&_"$path[$number]);
            
#Replace Underscore with Space
            
$path[$number] = str_replace("_"" "$path[$number]);
            
#Replace Tilde with Question Mark
            
$path[$number] = str_replace("~""?"$path[$number]);
            
#Erase .php file extension
            
$path[$number] = str_replace(".php"""$path[$number]);
            
#Capitalize All Words
            
$path[$number] = ucwords($path[$number]);
    }
# First It Checks The Last Element To See If It's An Ignore.  If not, print it and quit
$number $totalelements-1;
if(
check_ignore($ignore,$path[$number])){
    
printf("%s"$path[$number]);
    exit;
}
# Next We Either Print The Root or the Directory in the element below the last element.
else {
    if (
$totalelements==2) {
        
# Print out the Link to the Homepage.
        
printf("%s"$roottitle);
        exit;
    }
    else {
        
# Print the directory in the element below the last element
        
$number $totalelements-2;
        
printf("%s",$path[$number]);
        exit;
    }

}

?> 


Usage Example


<?php
##################################################
##                                              ##
##              title.php v1.0                  ##
##              Copyright 2001                  ##
##                                              ##
##       Jim Fletcher jim@websitecode.com       ##
##                                              ##
##  Free to distribute as long as this notice   ##
##  remains. You cannot charge for this work or ##
##  any derivatives thereof. No warranties on   ##
##  this program are made or implied.           ##
##                                              ##
##################################################
## Revisions:                                   ##
## 1.0                                          ##
##                                              ##
## You may make any modifications to this script##
## to best fit your needs, but if you find some-##
## thing wrong, let me know at                  ##
##            jim@websitecode.com               ##
##################################################
#
# To run this script you will need PHP enabled on
# your server, and the PHP call:
#    include("/path-to-this-script/title.php");
# inserted within the PHP pages you want it to run on.
#
# NOTE: the "/path-to-this-script/" listed above
# means change it to the location on YOUR
# webserver or delete it if the path.php is in the
# same directory as the calling page.
#
####################################
#          USER VARIABLES          #
####################################
#What is the path that is going to be parsed? You may pass comment this out and pass the $originalpath as a variable from the calling page, but in testing the $PHP_SELF variable came from the original calling page, not the path.php page.
$originalpath $PHP_SELF;

#What is the Base URL? (usually the domain name)
$urlbase "http://".$HTTP_HOST;
#$urlbase = "http://www.websitecode.com"; # Uncomment if the above line isn't working for you.

# What Link Text Do You Want To Appear for the link to the base URL?
$roottitle "Home";

# What file do you want to not print a link to? (drop the .php suffix & capitalize the filename)
$ignore = array("Index","Home","Default");

#######################################
# Do not modify beneath this point unless you know what you're doing!

function check_ignore($ignore,$referer){
  if (
count($ignore)){
    global 
$errors;
    
$found true;
    
#$referer = $path[$number];
    
for ($x=0$x count($ignore); $x++){
      if (
$ignore[$x] == $referer){
        
$found false;
      }
    }
    return 
$found;
  } else {
    return 
true//Not a good idea, if empty, it will allow it.
  
}
}


#Splits the path into an array using a forward slash
$path explode ("/"$originalpath);
#Counts How many elements are in the array so the loop below knows how long to loop
$totalelements count ($path);

# Loops thru the array formatting each element
    
for($number=1$number<$totalelements $number++) {
        
#Appends the next directory or file down to the URL
        
$urlbase $urlbase "/" $path[$number];
        
# Do Some Formatting on the Link Text
            #Replace Triple Underscore with Ampersand Surrounded By Underscores to be later converted to spaces
            
$path[$number] = str_replace("___""_&_"$path[$number]);
            
#Replace Underscore with Space
            
$path[$number] = str_replace("_"" "$path[$number]);
            
#Replace Tilde with Question Mark
            
$path[$number] = str_replace("~""?"$path[$number]);
            
#Erase .php file extension
            
$path[$number] = str_replace(".php"""$path[$number]);
            
#Capitalize All Words
            
$path[$number] = ucwords($path[$number]);
    }
# First It Checks The Last Element To See If It's An Ignore.  If not, print it and quit
$number $totalelements-1;
if(
check_ignore($ignore,$path[$number])){
    
printf("%s"$path[$number]);
    exit;
}
# Next We Either Print The Root or the Directory in the element below the last element.
else {
    if (
$totalelements==2) {
        
# Print out the Link to the Homepage.
        
printf("%s"$roottitle);
        exit;
    }
    else {
        
# Print the directory in the element below the last element
        
$number $totalelements-2;
        
printf("%s",$path[$number]);
        exit;
    }

}

?>


Rate This Script





Search



This Category All Categories