Getting numeric value from last section of a URL

This is a discussion on Getting numeric value from last section of a URL within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All, Background: I have a mySQL/PHP Driven site, which now needs data paging. For SEO reasons, we use ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-06-2006
Simon Harris
 
Posts: n/a
Default Getting numeric value from last section of a URL

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!


Reply With Quote
  #2 (permalink)  
Old 12-06-2006
ZeldorBlat
 
Posts: n/a
Default Re: Getting numeric value from last section of a URL


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>";

Reply With Quote
  #3 (permalink)  
Old 12-06-2006
Simon Harris
 
Posts: n/a
Default Re: Getting numeric value from last section of a URL

Great, thanks!
"ZeldorBlat" <zeldorblat@gmail.com> wrote in message
news:1165437271.872020.265170@n67g2000cwd.googlegr oups.com...
>
> 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>";
>


--------------------------------------------------------------------------------
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!


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:20 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0