473,830 Members | 2,124 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 6122
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
30562
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
2018
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
9786
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
9641
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
10769
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
10523
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,...
1
7741
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
5778
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4409
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
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3073
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.