newbie
newbie

Reputation: 24645

Parsing number value from SEF url in PHP

I have SEF urls like /sitename/section/12-news-title and number 12 is id of the news. I need to get that number 12 in my php code, is there any out of the box method in PHP for this?

Upvotes: 2

Views: 293

Answers (2)

Pavunkumar
Pavunkumar

Reputation: 5345

<?php 

$_GET['id'] = "/sitename/section/12news-title"; // For example 
if ( preg_match ( '/\d+/',$_GET['id'] ,$val ) )
 {
 print_r ( $val ) ; // Now $val will have the matched things. 
 }
 else
 {
 print "Not matched \n";
 } 

?>

Upvotes: 3

Ben Shelock
Ben Shelock

Reputation: 20985

Depends how your URLs are being manipulated. It will be something like $_GET['id'] but it's hard to say without seeing how your URLs are being changed. Have a look in your .htaccess file and you should be able to work it out.

Upvotes: 1

Related Questions