Example 1 — Split on a Pipe Delimiter
Store three fields separated by | and read them one at a time with stream_get_line().
<?php
$stream = fopen("php://memory", "r+");
fwrite($stream, "red|green|blue");
rewind($stream);
echo stream_get_line($stream, 100, "|"), PHP_EOL;
echo stream_get_line($stream, 100, "|"), PHP_EOL;
echo stream_get_line($stream, 100, "|"), PHP_EOL;
fclose($stream); How It Works
- The memory stream holds the text "red|green|blue".
- Each stream_get_line() call stops at the next | and omits that character.
- Three calls print red, green, and blue on separate lines.
- The delimiter is consumed but not returned.

