how it is getting this value in reg exp for php

Discussion in 'PHP' started by ironmankho, Nov 28, 2010.

  1. #1
    how it is getting this value in reg exp for php

    <li><b>Paperback:</b> 367 pages</li>

    i need only "367"

    i am using strpos and substr but now i want in regExp...

    thanks
     
    Solved! View solution.
    ironmankho, Nov 28, 2010 IP
  2. underground-stockholm

    underground-stockholm Guest

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if (preg_match('%Paperback:</b>\s*([0-9]+)\s+pages%s', $str, $matches))
    { echo "matched $matches[1]\n"; }
    else
    { echo "didn't match\n"; }
     
    underground-stockholm, Nov 28, 2010 IP
  3. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks for this ......

    it is working -> return

    Paperback: 367 pages

    but i want only "367"
     
    Last edited: Nov 28, 2010
    ironmankho, Nov 28, 2010 IP
  4. #4
    if (preg_match('/\d+/', '<li><b>Paperback:</b> 367 pages</li>', $matches))
    {
    echo $matches[0] . "\n";
    }
    else
    {
    echo "didn't match\n";
    }
     
    drctaccess, Nov 29, 2010 IP