Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] String related issue


[SOLVED] String related issue

Reply
  #1 (permalink)  
Old 09-29-08, 08:23 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] String related issue

I have a variable:

Code:
$comment_count = substr($anchor, $quote_mark_left +1, $quote_mark_right - $quote_mark_left -1);
The $comment_count store a string value, something like:

Code:
1 comment
2 comment
5 comment
....
I want to get only the number, which is the best way to do this ? I need this output:

Code:
1
2
5
Thanks!
Reply With Quote
  #2 (permalink)  
Old 09-29-08, 09:20 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:

preg_match_all('~(?:^|\n)(\d+)[ ]+~'$comment_count$numbers);
echo 
'<pre>'print_r($numbers[1], true), '</pre>'
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OOP C-Sharp DB Access Wrapper Question digioz ASP.NET 1 09-08-08 09:54 AM
search function using dot net nishudude_13 Windows .NET Programming 1 08-28-08 11:28 AM
[SOLVED] searching through a grid view painthu ASP.NET 5 05-21-08 10:11 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 08:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.