note 87862 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Sat, 27 Dec 2008 16:46:47 +0000 |
| Subject: | note 87862 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148560@lists.php.net to get a copy of this message | ||
Note Submitter: RodolfoRG
----
linebreak type are transparent to strpos() (dos, mac and unix), but not to all functions (like
preg_split).
<?php
$text = "Hello,\r\n\r\nWorld!";
$dos = strpos("\r\n",$text) !== false; // DOS line break?
$mac = strpos("\r\n",$text) === false && strpos("\r",$texto) !== false;
// Mac line break?
$unix = strpos("\r",$text) === false; // Unix line break?
if ($dos)
echo "DOS\n";
if ($mac)
echo "Mac\n";
if ($unix)
echo "Unix\n";
?>
results always on Unix.
But with preg_split(), it makes difference!
<?php
$text = "Hello,\r\n\r\nWorld!";
$dosLines = preg_split("/\r\n\r\n/",$text,-1);
print_r($dosLines);
$unixLines = preg_split("/\n/\n",$text,-1);
print_r($unixLines);
?>
This prints:
Array
(
[0] => Hello,
[1] => World!
)
Array
(
[0] => Hello,
[1] =>
[2] => World!
)