Re: [PHP] explode a string

2005-04-20 Thread Saswat Praharaj
explode by ,
$output1 = explode(,,$string);

use a loop and explode  array $output1 by : 

Hope this helps.

Saswat

On 4/18/05, Sebastian [EMAIL PROTECTED] wrote:
 $string = '4:gaming,5:hardware,3:software,8:security';
 
 what is the best way to explode then loop this string after its taken apart.
 
 output should be something like:
 
 $id = 4
 $cat = gaming
 
 etc..
 
 im just looking for the best/fastest way to do this. the string can grow to
 200 or so bytes, maybe more.
 
 should i list(), while(), explode it, or should i explode it and foreach it?
 or..?
 
 thanks.
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] handling file upload (OT not exactly PHP)

2005-04-20 Thread Saswat Praharaj
Hello , 

Need to do handle a file upload done via http POST.

I can read the content length and from POST and get the contents.
But, how do I get the exact file ?? 

Eg. suppose for  uploading a .doc file I could see that it sends the
font type and other parameters also..

I am not sure how does it will matter when I am extracting the exact
file from the POST request .

Again, how would I extract the exact file ??

Would appreciate any pointers or someone giving me some headstart .

Thanks and Regards,
-Saswat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Need help: change a string in a file

2005-04-08 Thread Saswat Praharaj
Richard,

Thanks for the answer.
I understand that I can't do it the way I wanted .

I have changed my design.

Thanks ALL who answered.

-Saswat


On Apr 7, 2005 8:18 AM, Richard Lynch [EMAIL PROTECTED] wrote:
 On Wed, April 6, 2005 10:07 am, Saswat Praharaj said:
  I need some help in searching string in a file.
 
  My requirement is to search the string,append something to the string .
  Write the string back to the file without changing other parts of the
  file.
 
  e.g
  Suppose I have the following string in a file
 
 
  Set-Cookie: T_COOKIE=127.0.0.1-saswat-9; path=/
 
 
  The fixed string is Set-Cookie: T_COOKIE=and rest of the string is
  variable.
  I would like to change the string 127.0.0.1-saswat-9  to say
  127.0.0.1-saswat-9-1234
 
 Problem is, that's *MORE* bytes than are already there.
 
 You can't just smush a few more bytes in.
 
 You will *HAVE* to write out a new file.
 
 But you can read in only the first couple hundred bytes until you find
 your Set-Cookie: T_COOKIE, and then you write out the stuff before that,
 write out your new data, then read/write the whole rest of the file.
 
 You may also want to consider using, say, awk or sed or whatever from
 http://php.net/exec -- I don't expect them to be that much faster than
 PHP, but what do I know?
 
  My constraint is : I don't want to read the whole file into a buffer
  and work on that buffer as the file can be very large , sometimes more
  than 10 mb.
 
  My advantage is : I know that I will get the search string in first
  200 bytes of the file , so I just need to read 200 bytes,play with
  that and write it back (overwriting the first 200 bytes with new 200
  some bytes) ..
 
 If it's really 200 bytes for 200 bytes, yeah, fopen(..., 'r+') will work.
 
 But if you can't squeeze your bytes into the same space as is already
 there, you can't do that.
 
 You might also be able, for the future, to start using:
 127.0.0.1-saswat-9-000 and then you'd be able to replace up to
  and get back something you can easily read/write/format to be
 meaningful.
 
 --
 Like Music?
 http://l-i-e.com/artists.htm
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Need help: change a string in a file

2005-04-06 Thread Saswat Praharaj
Hi All,

I need some help in searching string in a file.

My requirement is to search the string,append something to the string .
Write the string back to the file without changing other parts of the file.

e.g  
Suppose I have the following string in a file 


Set-Cookie: T_COOKIE=127.0.0.1-saswat-9; path=/


The fixed string is Set-Cookie: T_COOKIE=and rest of the string is variable.
I would like to change the string 127.0.0.1-saswat-9  to say
127.0.0.1-saswat-9-1234

My constraint is : I don't want to read the whole file into a buffer
and work on that buffer as the file can be very large , sometimes more
than 10 mb.

My advantage is : I know that I will get the search string in first
200 bytes of the file , so I just need to read 200 bytes,play with
that and write it back (overwriting the first 200 bytes with new 200
some bytes) ..

Would appreciate any help or pointers.

Thanks,
-Saswat

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] newbie:changing variable to type resource

2005-03-14 Thread Saswat Praharaj
Hi All,

I am new to PHP, stuck with a problem and need your help.

I would like to change a variable to type resource.
I searched in php.net and in google but did not find anything helpful.

Now , why I would like to do that...

I am writing a socket application which will accept connection from
browser,receive data and write the data sent by browser into another
open socket.Receive data from the open socket and write it back to the
browser.

When there are more than one client(browser) connecting to my program
,I am saving the connection information (socket ID)for browser
connections in a plain text file.

I intend to retrive the socket ID information and do a
socket_write(..) with socket ID as the first parameter, but I am
getting an error that I cant convert any type to a resource type. Is
there any workaround ??

Is it going to help me if I use session information ?

I am not using apache.

I may be wrongly designing the program.

Would appreciate all your suggestion and help.

Thanks,
-Saswat

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie:changing variable to type resource

2005-03-14 Thread Saswat Praharaj
Richard,

Thanks for the quick reply.

Here is what I am trying to do :

I am trying to tunnel some http packets from the browser to a PC which
is inside a private network/firewall.

The PC in the pvt. netwok sends a request to my server at regular interval.
When the browser wants to send some packets to the PC (which it can't
without opening a port in the firewall), it sends the packets to my
program  and my program tunnels those packets in the response to the
request messeges coming from the PC inside the firewall.

I am able to do it when there is only one PC and one browser tries to
access it by storing the socket ID of the browser connection in a
temporary variable in my program ,but I need  some kind of mechanism
to store socket IDs for connections coming from multiple browsers.
Without which I can't distinguish between different connections.

Regards,
-Saswat


On Mon, 14 Mar 2005 09:11:46 -0800 (PST), Richard Lynch [EMAIL PROTECTED] 
wrote:
  I am new to PHP, stuck with a problem and need your help.
 
  I would like to change a variable to type resource.
  I searched in php.net and in google but did not find anything helpful.
 
  Now , why I would like to do that...
 
  I am writing a socket application which will accept connection from
  browser,receive data and write the data sent by browser into another
  open socket.Receive data from the open socket and write it back to the
  browser.
 
  When there are more than one client(browser) connecting to my program
  ,I am saving the connection information (socket ID)for browser
  connections in a plain text file.
 
  I intend to retrive the socket ID information and do a
  socket_write(..) with socket ID as the first parameter, but I am
  getting an error that I cant convert any type to a resource type. Is
  there any workaround ??
 
  Is it going to help me if I use session information ?
 
  I am not using apache.
 
  I may be wrongly designing the program.

 The design just maybe might be fine in theory, but in practice...

 A socket connection can't be shared across PHP instances, I don't think.

 Certainly not by writing the resource into a text file.

 You *MIGHT* be able to write the resource into shared memory
 http://php.net/shmop but I doubt that will work at all, and even if it
 does, having two programs reading/writing the same socket resource at one
 time sounds like a recipie for disaster.

 Why do you want to share this socket across two PHP programs?

 What exactly are you doing?

 I suspect that the design is not right, even in theory, but can't be sure.

 --
 Like Music?
 http://l-i-e.com/artists.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php