Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-22-2005, 10:08 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Adding commas question

Can someone please tell me how I would add commas after the room names and user names in this piece of code. I don't want and comma after the last room name or lat user name, though, if possible.

PHP Code:
 $port 10010;
function 
getServerAPI$apiCommand )
{
global 
$port;
$result "";
$fp fsockopen("localhost"$port, &$errno, &$errstr2);
if(!
$fp)
{
echo 
"$errstr ($errno)\n";
}
else
{
fputs($fp,"GET /?".$apiCommand." HTTP/1.0\n\n");
$header true;
while(!
feof($fp))
{
$line fgets($fp,128);
if ( 
$header == false $result .= $line;
if ( 
trim($line) == "" $header false;
}
fclose($fp);
}
return 
$result;
}
$userList getServerAPI"api.UserList" );
$roomList getServerAPI"api.RoomList" ); 
Reply With Quote
  #2  
Old 09-22-2005, 10:28 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't see any User- or Room Names in this Code ...
Or in other Words:

How does $userList look like?
Reply With Quote
  #3  
Old 09-22-2005, 11:54 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here is the code I am currently using, but as you can see there is an extra comma after the room names. It happens with more than one user, too. That's why I thought with fresh code as above, it might be easier to do the commas right.

PHP Code:
$port 10010;
function 
getServerAPI($apiCommand)
{
    global 
$port;
    
$result "";
    
$fp fsockopen("localhost"$port, &$errno, &$errstr2);
    if(!
$fp)
    {
        echo 
"$errstr ($errno)\n";
    }
    else
    {
        
fputs($fp,"GET /?".$apiCommand." HTTP/1.0\n\n");
        
$header true;
        while(!
feof($fp))
        {
            
$line fgets($fp,128);
            
// print $line;
            
if ($header == false)
   if(
$apiCommand!='api.UserList') {
   
$result .= trim($line) . ', ';
   }else {
   
$result .= substr($line0, -1); // trim the last ', '
   
}
            if (
trim($line) == "")
                
$header false;
        }
        
fclose($fp);
    }
    return 
substr($result0, -2); // trim the last ', '
}
$userCount getServerAPI"api.UserList" );
$roomList getServerAPI"api.RoomList" ); 
This is what it looks like after we get the roomlist and the userlist. If you need to see the template, let me know.
Attached Images
File Type: gif Snap1.gif (6.3 KB, 0 views)
Reply With Quote
  #4  
Old 09-22-2005, 11:56 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, so where do you want to add commas (as there already seem to be some)?
Reply With Quote
  #5  
Old 09-22-2005, 11:57 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I edited my post above.
Reply With Quote
  #6  
Old 09-22-2005, 12:10 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't really understand the Code
PHP Code:
$port 10010;
function 
getServerAPI($apiCommand)
{
    global 
$port;
    
$result "";
    
$fp fsockopen("localhost"$port, &$errno, &$errstr2);
    if (!
$fp)
    {
        echo 
"$errstr ($errno)\n";
    }
    else
    {
        
fputs($fp,"GET /?".$apiCommand." HTTP/1.0\n\n");
        
$header true;
        while(!
feof($fp))
        {
            
$line fgets($fp,128);
            echo(
"Raw Data: '$line'");
            if (
$header == false)
            {
                
$result .= trim($line) . ', ';
            }
            if (
trim($line) == "")
            {
                        
$header false;
            }
            }
        
fclose($fp);
    }
    return 
substr($result0, -2); // trim the last ', '
}
$userCount getServerAPI"api.UserList" );
$roomList getServerAPI"api.RoomList" ); 
What's the Raw Data?
Reply With Quote
  #7  
Old 09-22-2005, 12:32 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's for RealChat. The roomList is for the rooms and the userList is for the users. That's about all I know about it.

Here is the raw data.

Quote:
Raw Data: 'HTTP/1.1 200 OK 'Raw Data: 'Date: Thu Sep 22 09:30:01 EDT 2005 'Raw Data: 'Server: RealChat Server Version 2.2.2d, http control server 'Raw Data: 'Cache-Control: no-cache, must-revalidate 'Raw Data: 'Expires: Mon, 26 Jul 1997 05:00:00 GMT 'Raw Data: 'Pragma: no-cache 'Raw Data: 'Connection: close 'Raw Data: 'Content-Type: text/html; charset=iso-8859-1 'Raw Data: ' 'Raw Data: ' 'Raw Data: ' 'Raw Data: 'HTTP/1.1 200 OK 'Raw Data: 'Date: Thu Sep 22 09:30:01 EDT 2005 'Raw Data: 'Server: RealChat Server Version 2.2.2d, http control server 'Raw Data: 'Cache-Control: no-cache, must-revalidate 'Raw Data: 'Expires: Mon, 26 Jul 1997 05:00:00 GMT 'Raw Data: 'Pragma: no-cache 'Raw Data: 'Connection: close 'Raw Data: 'Content-Type: text/html; charset=iso-8859-1 'Raw Data: ' 'Raw Data: 'The Bear's Den 'Raw Data: 'The Lobby 'Raw Data: 'Executive Den 'Raw Data: ''
Reply With Quote
  #8  
Old 09-22-2005, 12:34 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Simplest solution in general to a problem like this is to put all usernames/roomnames into an array. Then when all names are collected do:
PHP Code:
$usersstring explode(", "$usersarray); 
Reply With Quote
  #9  
Old 09-22-2005, 12:41 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And how would you go about putting them all into an array?
Reply With Quote
  #10  
Old 09-22-2005, 12:44 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$port 10010;
function 
getServerAPI($apiCommand)
{
    global 
$port;
    
$result "";
    
$fp fsockopen("localhost"$port, &$errno, &$errstr2);
    if (!
$fp)
    {
        echo 
"$errstr ($errno)\n";
    }
    else
    {
        
fputs($fp,"GET /?".$apiCommand." HTTP/1.0\n\n");
        
$header true;
        while(!
feof($fp))
        {
            
$line trim(fgets($fp,128));
            if (
$header == false AND $line != '')
            {
                
$result .= "$line, ";
            }
            else if (
$line == '')
            {
                        
$header false;
            }
            }
        
fclose($fp);
    }
    return 
substr($result0, -2); // trim the last ', '
}
$userCount getServerAPI"api.UserList" );
$roomList getServerAPI"api.RoomList" ); 
Should work.
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 07:22 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05070 seconds
  • Memory Usage 2,323KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete