Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would use <a href="http://ch.php.net/manual/en/function.sscanf.php" rel="nofollow">sscanf</a></p> <p>Untested example:</p> <pre><code>list($node_id, $pdf_id) = sscanf($url, "node/%d/pdf/%d"); </code></pre> <p><code>$node_id</code> contains the node id, <code>$pdf_id</code> contains the pdf id. According to your comment: Yes, you can output it with e.g. <code>echo $pdf_id;</code>.</p> <p>If you need them both in an array, you can remove the <code>list()</code> method, doing it like this: </p> <p><code>$ids = sscanf($url, "node/%d/pdf/%d");</code>. </p> <p>This returns an array with both node and pdf id in <code>$ids</code>.</p> <p>Finally, if you just need the pdf id, you could do </p> <p><code>$id = sscanf($url, "node/95/pdf/%d");</code>.</p> <p>I just showed how to fetch both because I assumed you may need both numbers from your url.</p> <p><strong>Edit</strong><br> 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.</p> <p><strong>Edit 2</strong> <code>list($node_id, $sub, $sub_id) = sscanf($url, "node/%d/%[^/]/%d");</code> will get you the "pdf" and it's id separate instead of "node/%d/%s/%d". This is because char <code>/</code> is also matched by <code>%s</code>. Using <code>%[^/]</code> matches everything except the forward slash.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload