Search code examples
phpfgets

Fgets() but on a string instead of a file?


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.


Solution

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

    Probably you need substr()