473,802 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why no [fragment] in parse_url($_SER VER['PHP_SELF'])?

I'm trying to identify which named anchor is currently being viewed on a
page. Although the address bar of my browser shows #whatever appended to
the end of the url, I can't seem to find it in a variable.

My efforts below return no value for ANYTHING except [path]. Am I missing
something?

$url = parse_url($_SER VER['PHP_SELF']);

$scheme = ($url[scheme]);
$host = ($url[host]);
$port = ($url[port]);
$user = ($url[user]);
$pass = ($url[pass]);
$path = ($url[path]);
$anchor = ($url[fragment]);

echo $scheme." = scheme<br>";
echo $host." = host<br>";
echo $port." = port<br>";
echo $user." = user<br>";
echo $pass." = pass<br>";
echo $path." = path<br>";
echo $anchor." = anchor<br>";

Jul 17 '05 #1
13 6119
deko wrote:
I'm trying to identify which named anchor is currently being viewed on a
page. Although the address bar of my browser shows #whatever appended to
the end of the url, I can't seem to find it in a variable.

My efforts below return no value for ANYTHING except [path]. Am I missing
something?

$url = parse_url($_SER VER['PHP_SELF']);

$scheme = ($url[scheme]);
$host = ($url[host]);
$port = ($url[port]);
$user = ($url[user]);
$pass = ($url[pass]);
$path = ($url[path]);
$anchor = ($url[fragment]);

echo $scheme." = scheme<br>";
echo $host." = host<br>";
echo $port." = port<br>";
echo $user." = user<br>";
echo $pass." = pass<br>";
echo $path." = path<br>";
echo $anchor." = anchor<br>";


You will not be able to retrieve anchor with a $_SERVER variable since it isn't
transmitted to the server but handled on the client.

/p

--
http://www.pergustafsson.com/
Jul 17 '05 #2
> You will not be able to retrieve anchor with a $_SERVER variable since it
isn't
transmitted to the server but handled on the client.


Hi and thanks for the reply.

I was reading up on anchors at
http://www.w3.org/TR/REC-html40/stru....html#h-12.1.2
The section: "12.2.3 Anchors with the id attribute" talks about using id's -
The id attribute can act as more than just an anchor name (e.g., style sheet
selector, processing identifier, etc.).

Do you think I can identify what is being viewed on the page if I use the id
attribute in the link? Other options?
Jul 17 '05 #3
> I was reading up on anchors at
http://www.w3.org/TR/REC-html40/stru....html#h-12.1.2
The section: "12.2.3 Anchors with the id attribute" talks about using id's - The id attribute can act as more than just an anchor name (e.g., style sheet selector, processing identifier, etc.).

*** this goes in page which I am linking to:
<a id="test"></a>

*** this is on page I am linking from:
<p><a href="tech.php# test">test</a></p>

The problem may still be client-side (as opposed to server-side) processing.
Perhaps Javascript is the way to go? If I could find some examples...
Jul 17 '05 #4
deko wrote:
I'm trying to identify which named anchor is currently being viewed on a
page.**Although *the*address*ba r*of*my*browser *shows*#whateve r*appended*to
the end of the url, I can't seem to find it in a variable.


If the url http://www.domain.com/pagename.html#whatever the #whatever part
is not transmitted to the server. You'll need to deal with it on the client
side using Javascript.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #5
> If the url http://www.domain.com/pagename.html#whatever the #whatever part
is not transmitted to the server. You'll need to deal with it on the client side using Javascript.


10-4. That's what I am discovering. The goal here is to do different
things based on what section of the page is being viewed. Here's an
interesting article about using id's instead of names in anchors:
http://www.netmechanic.com/news/vol7/html_no6.htm

I've looked into Javascript a bit - but the question remains: how to
identify what anchor is currently beig viewed? If I can't do it in PHP how
to do it in Javascript?
Jul 17 '05 #6
deko wrote:
If the url http://www.domain.com/pagename.html#whatever the #whatever
part is not transmitted to the server. You'll need to deal with it on the

client
side using Javascript.


10-4. That's what I am discovering. The goal here is to do different
things based on what section of the page is being viewed. Here's an
interesting article about using id's instead of names in anchors:
http://www.netmechanic.com/news/vol7/html_no6.htm

I've looked into Javascript a bit - but the question remains: how to
identify what anchor is currently beig viewed? If I can't do it in PHP
how to do it in Javascript?


Probably best to ask the Javascript group if you haven't already -
comp.lang.javas cript

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #7
deko wrote:
If the url http://www.domain.com/pagename.html#whatever the #whatever part
is not transmitted to the server. You'll need to deal with it on the


client
side using Javascript.

10-4. That's what I am discovering. The goal here is to do different
things based on what section of the page is being viewed. Here's an
interesting article about using id's instead of names in anchors:
http://www.netmechanic.com/news/vol7/html_no6.htm

I've looked into Javascript a bit - but the question remains: how to
identify what anchor is currently beig viewed? If I can't do it in PHP how
to do it in Javascript?


try this:

<script language="javas cript">
var a = (window.locatio n.href.split('# ')) ;
document.write( a[1])
</script>

thanks for the question!

sadara
Jul 17 '05 #8
Sadara wrote:
deko wrote:
If the url http://www.domain.com/pagename.html#whatever the #whatever
part
is not transmitted to the server. You'll need to deal with it on the

client
side using Javascript.


10-4. That's what I am discovering. The goal here is to do different
things based on what section of the page is being viewed. Here's an
interesting article about using id's instead of names in anchors:
http://www.netmechanic.com/news/vol7/html_no6.htm

I've looked into Javascript a bit - but the question remains: how to
identify what anchor is currently beig viewed? If I can't do it in
PHP how
to do it in Javascript?


try this:

<script language="javas cript">
var a = (window.locatio n.href.split('# ')) ;
document.write( a[1])
</script>

thanks for the question!

sadara


of course, this doesn't strictly tell you which anchor is currently
being viewed, only which anchor was requested.

as far as i can see there is no window or document property
corresponding to the idea of 'last requested anchor' or 'live anchor' or
whatever.

sadara
Jul 17 '05 #9
Sadara wrote:
Sadara wrote:
deko wrote:
If the url http://www.domain.com/pagename.html#whatever the #whatever
part
is not transmitted to the server. You'll need to deal with it on the
client

side using Javascript.

10-4. That's what I am discovering. The goal here is to do different
things based on what section of the page is being viewed. Here's an
interesting article about using id's instead of names in anchors:
http://www.netmechanic.com/news/vol7/html_no6.htm

I've looked into Javascript a bit - but the question remains: how to
identify what anchor is currently beig viewed? If I can't do it in
PHP how
to do it in Javascript?


try this:

<script language="javas cript">
var a = (window.locatio n.href.split('# ')) ;
document.write( a[1])
</script>

thanks for the question!

sadara


of course, this doesn't strictly tell you which anchor is currently
being viewed, only which anchor was requested.

as far as i can see there is no window or document property
corresponding to the idea of 'last requested anchor' or 'live anchor' or
whatever.


But using deko's idea of using ids (eg <a id="foo" name="foo"></a>) you can
now do:

<script language="javas cript">
var a = (window.locatio n.href.split('# ')) ;
document.getEle mentById(a). <-- other stuff here
</script>

You could use it to alter the style or content of the element or surrounding
element.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
30556
by: Spidah | last post by:
How do I get the contents of the browser address bar with PHP - assuming it is possible? In javascript it is done with: unescape(window.location.pathname), but is there a php equivalent? Thanks Hamilton
3
6986
by: deko | last post by:
I use #currentlink in a nav list of links to indicate which page is currently being viewed. The code in the nav list looks like this: <p><a href="index.php">Home Page</a></p> <p><a href="contact.php">Contact</a></p> <p><a href="tech.php#tech01">tech01</a></p> <p><a href="tech.php#tech02">tech02</a></p> <p><a href="tech.php#tech03">tech03</a></p>
7
2016
by: Aaron Gray | last post by:
I just wanted to share some useful PHP functions that I have written while developing an application. http://www.cybercomms.org/PHP/utils.inc The .inc filename is just so it can be viewed, I use .php for include files usually. ~~~~~~~~~~~~~~ utils.php ~~~~~~~~~~~~~~~~ <?php
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.