Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Regular Expressions to extract an integer
Old 07-08-2010, 02:57 PM PHP Regular Expressions to extract an integer
Junior Talker

Posts: 1
Name: Dave Grant
Trades: 0
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
digitalpencil is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-08-2010, 08:14 PM Re: PHP Regular Expressions to extract an integer
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
preg_match('~<span class="redbtext" property="myspace:friendCount">(\d+)</span>~is'file_get_contents('http://www.myspace.com/rachelfurner'), $match);
  
echo 
'Result is: ' $match[0]; 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Regular Expressions to extract an integer
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37555 seconds with 12 queries