Results 1 to 2 of 2

Thread: PHP Regular Expressions to extract an integer

  1. #1
    digitalpencil Guest

    Question PHP Regular Expressions to extract an integer

    Hi,

    I'm new here but am looking for some advice on how to extract a specific string of text from a website.

    Basically, i want to echo back the friend count on a myspace profile page ( http://www.myspace.com/rachelfurner )

    I would like to extract the integer '9762' (and only the integer) from the following string: Rachel Furner has <span class="redbtext" property="myspace:friendCount">9724</span> friends.

    I gather i can do this by loading the page via file_get_contents and then using RegEx to extract the integer but am unsure as to the preg_match value for extracting this specific information.

    Any advise on the best way to do this whether via Regular Expressions or not, would be much appreciated.

    Thanks,

    Dave Grant

  2. #2
    Join Date
    May 2010
    Location
    San Diego
    Posts
    8

    Smile

    PHP Code:
    <?php

    preg_match
    ('/\<span class\=\"redbtext\" property\=\"myspace\:friendCount\"\>([0-9]+)\<\/span\>/'$string$matches);

    // This will be the count
    echo $matches[1];

    ?>
    I haven't tested this but it SHOULD work.

Similar Threads

  1. PHP Image Upload with Flash Editing
    By oddball25 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 15 Dec 2009, 04:19 PM
  2. CMS advice (php)
    By Littlened in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 07 Jul 2007, 05:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •