/    Sign up×
Community /Pin to ProfileBookmark

Getting the page’s name

Hey there,

I’ve been working on a new website and I’m trieing some stuff I haven’t done before, but I got a problem. For now I want to print the url of the current page, or the document name, which I can do having the url. I made a little piece of code in an included document. The problem is, the code is giving me the document name of the included doc, not from the page. (for example: index.php). How can I fix the code, so it does give me the right doc name?

Here’s the code:

[code=php]<?php
function printLink($link){
$link = $link;
$document = end(explode(“/”, __FILE__));

print($document);

}
?>[/code]

Thanks for thinking with me.

Mrpaplu

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@ryanlundAug 07.2009 — First things first why are you passing a 'link' variable to it? could you not simply pass the name of the page that is including it into the function. eg:

[code=php]
function printLink($link){
$document = end(explode("/",$link));

print($document);

}
[/code]


and then call it like

[code=php]

include("include_path/file.php");

echo printLink(__FILE__);

[/code]
Copy linkTweet thisAlerts:
@NogDogAug 07.2009 — If you just want the name of the main script:
[code=php]
$fileName = basename($_SERVER['SCRIPT_NAME']);
[/code]
Copy linkTweet thisAlerts:
@ryanlundAug 07.2009 — Haha, why didnt i think of that....feel quite stupid now..
×

Success!

Help @mrpaplu 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.6,
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,
)...