Jump to content

How to extract specific info from the url


misterm

Recommended Posts

Hi

 

Can anyone help with this?

 

If the url of a certain page on my site is http://www.mysite.com/category/books/345

 

I use <? $thisPage = $_SERVER['REQUEST_URI']; ?> to set $thisPage as "http://www.mysite.com/category/books/345"

 

What I really need to do now is set the variable $thisCategory to whatever comes between category/ and /345 keeping in mind that the number at the end will change for every category of the site.

 

The reason I can't just grab an existing variable for the category is because it is hissed in an ioncube encrypted file.

 

Any help would be so appreciated as this would save me hours and hours of work.

 

many thanks

 

Mr M

Hiyah,

 

I think I would try using regular expression to do that. I don't think there is a function to do it for you.

 

Just do a search for php and regular expression in google and you'll get loads of results and examples.

 

PHP covers two types of regexp in the help file too.

 

HTH!

 

wayjo

Thanks Little Guy

 

That outputs:  Array ( [0] => [1] => Category [2] => Branding [3] => 159 )

 

But am not sure how to use it to get "Branding".  :/

 

Yes, the format will lways be the same.

 

 

If it will always be formatted the same, you could do this:

 

$url = 'http://www.mysite.com/category/books/345';
$values = explode('/',$url);
print_r($values);

You can also do something like:

<?php
$url = 'http://www.mysite.com/category/books/345';
$purl = parse_url($url);
list ($dmy,$catagory,$type,$id) = explode('/',$purl['path']);
print_r($purl);
echo '$catagory: ' . $catagory . "\n";
echo '$type: ' . $type . "\n";
echo '$id: ' . $id . "\n";
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.