preg_match trouble

Posted on 2007-07-24
Medium Priority
Last Modified: 2011-09-20
Hello - trying to get the id out of a url like

<a href="http://www.somedomain.com/pagename.php?id=1730517" target="_blank">http://www.somedomain.com/pagename.php?id=1730517</a>

I want to simply get the value after id= so I am left with 1730517
I think this can be done with preg_match but I can't get it to work.  Can someone help?
Question by:lackiem
  • 2
LVL 54

Accepted Solution

b0lsc0tt earned 500 total points
ID: 19562625
Is the id always just numeric?

What expressions have you been trying?

You could try it this way ...

if (preg_match('/id=(\d+)/', $subject, $regs)) {
      $result = $regs[1];
} else {
      $result = "";

Let me know how this works or if you have a question.


Author Comment

ID: 19562700
Thanks - worked perfect!
LVL 54

Expert Comment

ID: 19562720
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question