Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need some help with a code for the title
Old 12-25-2011, 02:00 PM Need some help with a code for the title
Junior Talker

Posts: 2
Trades: 0
So, i've found a code that changes the "Title" but, for example my website reads "index.php" as "first/home page" But, its shows "Index | ChrisBeats.Com" instead of that i want it to be called "Home | ChrisBeats.Com"

Example: chrizzle.nl

I tried something but it doesnt seem to work:
Code:
<?php $siteName = 'ChrisBeats.com';

$fileName = $_SERVER['PHP_SELF'];
$fileName = explode('.', $fileName);
$pageName = $fileName[0];
$pageName = str_replace('/', '', $pageName);

if ($fileName = 'index.php') {
	echo "print Home" | $siteName";";
} else {
	echo "print ucfirst($pageName) . " | $siteName";";
}
?>
i want to make a exception if the file is "index.php" and set a manual title,
if the file isnt "index.php" it will use the code instead

Original code:
Code:
<?php $siteName = 'ChrisBeats.com';

$fileName = $_SERVER['PHP_SELF'];
$fileName = explode('.', $fileName);
$pageName = $fileName[0];
$pageName = str_replace('/', '', $pageName);

print ucfirst($pageName) . " | $siteName"; ?>
Could anyone help me with this?
Thanks in advance

Last edited by ChrisBeatsdotCom; 12-25-2011 at 02:02 PM..
ChrisBeatsdotCom is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-25-2011, 03:00 PM Re: Need some help with a code for the title
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
$pageName = $fileName[0] is NOT necessarily going to be the name of the page. index 0 is the FIRST cell of the array which will be the leftmost part of the path.

To get the page name reliably you need the rightmost part, which is in the last cell of the array.

PHP Code:
$array[sizeof($array))] or $array[count($array))] 
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-25-2011, 03:03 PM Re: Need some help with a code for the title
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Oh and you might want to do some case conversion in the comparison, to catch any variations from "index.php"
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-25-2011, 03:11 PM Re: Need some help with a code for the title
Junior Talker

Posts: 2
Trades: 0
i dont know what you mean by
Quote:
$pageName = $fileName[0] is NOT necessarily going to be the name of the page. index 0 is the FIRST cell of the array which will be the leftmost part of the path.

To get the page name reliably you need the rightmost part, which is in the last cell of the array.
Code:
$array[sizeof($array))] or $array[count($array))]
but i apreciate your reply though.
ChrisBeatsdotCom is offline
Reply With Quote
View Public Profile
 
Old 12-25-2011, 03:23 PM Re: Need some help with a code for the title
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP_SELF returns the entire path.

IE "/dir/dir/index.php", you are creating the array by splitting on the '.' (dot) this will give $array[0] will be "/dir/dir/index" NOT index.php.

Explode using the '/' then the last array element will be the page name complete with extension.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-27-2011, 05:57 PM Re: Need some help with a code for the title
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
It doesn't matter what you do if you keep the line:

if ($fileName = 'index.php')

Double equals please
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need some help with a code for the title
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23007 seconds with 12 queries