473,802 Members | 1,988 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
13 6119
Chris Hope wrote:
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
interesti ng 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.wri te(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
correspondi ng 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.


the split() method returns an array, so you'd need:

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

sadara

Jul 17 '05 #11

"Sadara" <sa*********@NO WAYdds.nl> wrote in message
news:41******** *************** @news.xs4all.nl ...
Chris Hope wrote:
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
>interesti ng 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.wri te(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
correspondi ng 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.


the split() method returns an array, so you'd need:

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

sadara


Thanks for the replies. I also heard that I could parse location.hash,
which will return anything from the hash (#) onwards in the current URI.
Does that sound like a better idea - or is it 6 of one, half dozen of the
other?
Jul 17 '05 #12
> the split() method returns an array, so you'd need:

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

sadara


How about something like this:

function anchorname(n) {
var a=(window.locat ion.hash);
if (document.getEl ementById(a)=n) {anchorname=tru e}
}

Here's how I would code my link in the nav list:

<a href="test.php# test01"
onClick="anchor name('test01',' #currentlink')" >test01</a>

What I'm trying to do is apply css id #currentlink to the link if that's
where the user has navigated to. So I figure the function can test for a
given anchor name, and then somehow apply a style element if the function
returns true.
Jul 17 '05 #13
deko wrote:
"Sadara" <sa*********@NO WAYdds.nl> wrote in message
news:41******** *************** @news.xs4all.nl ...
Chris Hope wrote:

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
>>interesti ng 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
>>identif y 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.w rite(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
correspondi ng 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.get ElementById(a). <-- other stuff here
</script>

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


the split() method returns an array, so you'd need:

<script language="javas cript">
var a = (window.locatio n.href.split('# ')[1]) ;
document.getE lementById(a). <-- other stuff here
</script>

sadara

Thanks for the replies. I also heard that I could parse location.hash,
which will return anything from the hash (#) onwards in the current URI.
Does that sound like a better idea - or is it 6 of one, half dozen of the
other?


it sounds better to me!
Jul 17 '05 #14

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
10538
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...
0
10063
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
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();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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

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.