vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Adding commas question (https://vborg.vbsupport.ru/showthread.php?t=96708)

Boofo 09-22-2005 10:08 AM

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" ); 


Andreas 09-22-2005 10:28 AM

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

How does $userList look like?

Boofo 09-22-2005 11:54 AM

1 Attachment(s)
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. ;)

Andreas 09-22-2005 11:56 AM

OK, so where do you want to add commas (as there already seem to be some)?

Boofo 09-22-2005 11:57 AM

I edited my post above. ;)

Andreas 09-22-2005 12:10 PM

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?

Boofo 09-22-2005 12:32 PM

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: ''

Marco van Herwaarden 09-22-2005 12:34 PM

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); 


Boofo 09-22-2005 12:41 PM

And how would you go about putting them all into an array?

Andreas 09-22-2005 12:44 PM

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.


All times are GMT. The time now is 10:52 PM.

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.01185 seconds
  • Memory Usage 1,789KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete