/    Sign up×
Community /Pin to ProfileBookmark

Customising this function

Hi guys.
I hope you can help me please.

I am wanting to generate my page <title>’s automatically to save our time a bit. However, this function I found doesn’t do what we need…

[code=php]
function getScriptName($url) {
$name = “Undefined Page”;
$pattern = “//[a-zA-Z0-9_-]+.php/”;
preg_match($pattern ,$url, $matches);

if(is_array($matches) && !empty($matches[0])) {
$name = $matches[0];
}

$name = str_replace(“/”, “”, $name);
$name = preg_replace(“/.(php¦¦html)/”, “”, $name);

return $name;
}
[/code]

This just states “index.php” if we’re in /staff/index.php for example

What we want:

[code]
URL Should show
—————————————————————-
/staff/index.php Staff
/staff/manager/deluser.php Staff – Manager – Deluser
/staff/manager/index.php Staff – Manager
/index.php Index
[/code]

Any help with this would be greatly appreciated

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SoreheadJun 24.2008 — This will do what you after

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php

function rtn_title ()
{
$path = substr($_SERVER['PHP_SELF'],1);
$elements = explode("/",$path);
$num_elements = count($elements);
for( $x=0; $x < $num_elements; $x++)
{
if($x==($num_elements-1)){
$dot = strpos($elements[$x],".");
$final_str = substr($elements[$x],0,$dot);
$title .= ucwords($final_str);
}
else {
$title .= ucwords($elements[$x])." - ";
}
}
return $title;
}


?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo rtn_title(); ?></title>
</head>

<body>


</body>
</html>

[/CODE]
Copy linkTweet thisAlerts:
@TeachauthorJun 24.2008 — Thank you!
×

Success!

Help @Teach spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...