preg_match trouble

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

<a href="" target="_blank"></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
    LVL 54

    Accepted Solution

    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

    Thanks - worked perfect!
    LVL 54

    Expert Comment

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now