For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2006 > Getting numeric value from last section of a URL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Getting numeric value from last section of a URL
Simon Harris

2006-12-11, 7:01 pm

Hi All,

Background:
I have a mySQL/PHP Driven site, which now needs data paging. For SEO
reasons, we use URL rewriting through out the site (So far, not one
querystring value is required). The URL of my 'paged' data will be something
like this: www.asite.com/dir/subdir/page2. What I need to do, is just get
the '2' from 'page2' which I can then use in my paging routine.

Progress so far:
I am quite new to PHP, heres what I have come up with:

$theURL = "/dir/subdir/page2"; // Define the URL, juse because I am on a
test page in the root (Would normally use $_SERVER{'REQUEST_URI'} to get the
URL)
print $theURL ."<br>";

$count = count(explode("/",undo_magic_quotes($theURL))); // Store the number
of dirs
print $count ."<br>";

// Print out the last dir section (I would expect this to be 'page2' but it
is empty!)
print "|" .$arr_bits[$count-1] ."|<br>";
print str_replace("page","",$arr_bits[$count-1]); // Here I am trying to
turn 'page2' into just '2'

Obviously I was just writing out to the page to see if I was on the right
track, not much luck so far!

Any help/advice will be much appreciated,

Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!

--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 815 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!


ZeldorBlat

2006-12-11, 7:01 pm


Simon Harris wrote:
> Hi All,
>
> Background:
> I have a mySQL/PHP Driven site, which now needs data paging. For SEO
> reasons, we use URL rewriting through out the site (So far, not one
> querystring value is required). The URL of my 'paged' data will be something
> like this: www.asite.com/dir/subdir/page2. What I need to do, is just get
> the '2' from 'page2' which I can then use in my paging routine.
>
> Progress so far:
> I am quite new to PHP, heres what I have come up with:
>
> $theURL = "/dir/subdir/page2"; // Define the URL, juse because I am on a
> test page in the root (Would normally use $_SERVER{'REQUEST_URI'} to get the
> URL)
> print $theURL ."<br>";
>
> $count = count(explode("/",undo_magic_quotes($theURL))); // Store the number
> of dirs
> print $count ."<br>";
>
> // Print out the last dir section (I would expect this to be 'page2' but it
> is empty!)
> print "|" .$arr_bits[$count-1] ."|<br>";
> print str_replace("page","",$arr_bits[$count-1]); // Here I am trying to
> turn 'page2' into just '2'
>
> Obviously I was just writing out to the page to see if I was on the right
> track, not much luck so far!
>
> Any help/advice will be much appreciated,
>
> Simon.
>
> --
> -
> * Please reply to group for the benefit of all
> * Found the answer to your own question? Post it!
> * Get a useful reply to one of your posts?...post an answer to another one
> * Search first, post later : http://www.google.co.uk/groups
> * Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
>
> --------------------------------------------------------------------------------
> I am using the free version of SPAMfighter for private users.
> It has removed 815 spam emails to date.
> Paying users do not have this message in their emails.
> Try SPAMfighter for free now!


You never assigned the return value of explode to $arr_bits:

$arr_bits = explode("/",undo_magic_quotes($theURL));
$count = count($arr_bits); // Store the number of dirs
print $count ."<br>";

print "|" .$arr_bits[$count-1] ."|<br>";

Simon Harris

2006-12-11, 7:01 pm

Great, thanks!
"ZeldorBlat" <zeldorblat@gmail.com> wrote in message
news:1165437271.872020.265170@n67g2000cwd.googlegroups.com...
>
> Simon Harris wrote:
>
> You never assigned the return value of explode to $arr_bits:
>
> $arr_bits = explode("/",undo_magic_quotes($theURL));
> $count = count($arr_bits); // Store the number of dirs
> print $count ."<br>";
>
> print "|" .$arr_bits[$count-1] ."|<br>";
>


--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 815 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com