Fgets()但是在字符串而不是文件上?

I can do the following:

$fopen = fopen($file_name, 'r');
$data = fgets($fopen, 16384);
fclose($fopen);

But is their any way I could emulate the same functionality but on a string (instead of using a file name)?

$string = file_get_contents($file_name); /* just for demonstration purposes */
$data = /* do something here...*/

Hope that made sense.

There are lots of function defined for String manipulation here. You can choose any of them which fulfills your requirements.

Probably you need substr()

Humm... Not sure what you want but have you looked into substr()?

$string = file_get_contents($file_name); /* just for demonstration purposes */
$data = substr($string, 0, 16384);

Or maybe do you want ton consume a part of the string for each call to the function?

$parts = explode("
", $data);

foreach ($parts as $key => $value) {  
    $parts[$key] = substr($parts[$key], 0, 16384);  
}

This manual page documents a custom stream wrapper that can be used to give

read/write access to a named global variable using standard filesystem stream functions such as fread(). The var:// protocol implemented below, given the URL "var://foo" will read/write data to/from $GLOBALS["foo"].

This would allow you to do:

$fp = fopen('var://string', 'r');
$data = fgets($fp, 16384);

to 'fread() from $string'.