Just looing to do the following :
Extract the Page Number from a url like the following :
http://localhost/Lifestyle_And_Dating/Dating/Page_1
POssible values for page arre ... Page_1 to Page_99.
After extracting this from the url and storing it in a variable, I want to remove it from the source sttring (url)), so I am just left with
http://localhost/Lifestyle_And_Dating/Dating/
Many Thanks
Simple RegEx, difficult for me :(
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Code: Select all
<?php
$input = "http://localhost/Lifestyle_And_Dating/Dating/Page_1";
$matches = preg_split("/\/(Page_)/", $input);
print_r($matches)
?>Code: Select all
Array
(
[0] => http://localhost/Lifestyle_And_Dating/Dating
[1] => 1
)You don't need regex for this.
dirname()
Code: Select all
<?
$url = "http://localhost/Lifestyle_And_Dating/Dating/Page_1";
$stripped_url = dirname($url);
?>Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
probably he needs the page number for some purpose as well...pickle wrote:You don't need regex for this.
dirname()Code: Select all
<? $url = "http://localhost/Lifestyle_And_Dating/Dating/Page_1"; $stripped_url = dirname($url); ?>
You're 100% right. Had I fully read the question I would have noticed that :missing emoticon for d'oh!:raghavan20 wrote:probably he needs the page number for some purpose as well...
As that's the case, you can use basename() to get the file name. Though I can see now that regex may be simpler to some(I wouldn't use it here, but that's just me).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.