473,789 Members | 2,422 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 6116
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
6985
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
2015
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
9511
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
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
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
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
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.