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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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! |
|
|||
|
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>"; |
|
|||
|
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! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|