Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7595937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:47:50+00:00 2026-05-30T21:47:50+00:00

if I have this url: node/95/pdf/1 . How will I able to get the

  • 0

if I have this url: node/95/pdf/1. How will I able to get the numeric/value 1? Tried the parse_url but gave me the wrong output.

PS: the value 1 is just an example, the id is dynamic depends on what the user click.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:47:51+00:00Added an answer on May 30, 2026 at 9:47 pm

    I would use sscanf

    Untested example:

    list($node_id, $pdf_id) = sscanf($url, "node/%d/pdf/%d");
    

    $node_id contains the node id, $pdf_id contains the pdf id. According to your comment: Yes, you can output it with e.g. echo $pdf_id;.

    If you need them both in an array, you can remove the list() method, doing it like this:

    $ids = sscanf($url, "node/%d/pdf/%d");.

    This returns an array with both node and pdf id in $ids.

    Finally, if you just need the pdf id, you could do

    $id = sscanf($url, "node/95/pdf/%d");.

    I just showed how to fetch both because I assumed you may need both numbers from your url.

    Edit
    seeing all the other answers after posting my solution, I am wondering why everyone is solving this with multiple functions when there is a function available that does exactly what he needs: parsing a string according to a format. This also leads to less sql-injection prone code IMHO. And it doesn’t break something when the url gets extended or query strings are appended.

    Edit 2
    list($node_id, $sub, $sub_id) = sscanf($url, "node/%d/%[^/]/%d"); will get you the “pdf” and it’s id separate instead of “node/%d/%s/%d”. This is because char / is also matched by %s. Using %[^/] matches everything except the forward slash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this url: www.example.com/test.php?page=4 How do i retrieve the value of
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I'm using node.js but I have a feeling this isn't necessarily related to just
Say we have a class like this: import java.net.URL import xml._ class SearchData(xml: Node)
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url
I have this in my CSS file: body {style.css (line 3) background:#CDF8FF url(images/final_bg.jpg) no-repeat
I have this background, the css code is: body { background: #FFF url('images/bg.png') no-repeat
I have this piece of code: <table style=background-image: url(path/to_image.png)> And when I load it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.