Jump to content

Is my code ok ?


ShaolinF

Recommended Posts

Hi Guys

I am using the func below to get the last number from the URL. It works, but I want to know if there is a better way to do it:

 

example url: mysite.com/courses/100/ (100 is the post id)

 

//Get the 100 from the URL

$current_uri = $_SERVER['REQUEST_URI'];

$data = explode("/", $current_uri);

$post_id = $data[count($data)-2];

$post_id = filter_var($post_id, FILTER_VALIDATE_INT);

echo "The number is" . $post_id;

 

Link to comment
https://forums.phpfreaks.com/topic/182952-is-my-code-ok/
Share on other sites

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.