note 87862 added to function.strpos
| From: | RodolfoRG at osu1 dot php dot net | Date: | Sat, 27 Dec 2008 16:37:43 +0000 |
| Subject: | note 87862 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148559@lists.php.net to get a copy of this message | ||
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!
)
----
Server IP: 69.147.83.197
Probable Submitter: 201.79.32.218
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/87862
Del: integrated -- https://master.php.net/note/delete/87862/integrated
Del: useless -- https://master.php.net/note/delete/87862/useless
Del: bad code -- https://master.php.net/note/delete/87862/bad+code
Del: spam -- https://master.php.net/note/delete/87862/spam
Del: non-english -- https://master.php.net/note/delete/87862/non-english
Del: in docs -- https://master.php.net/note/delete/87862/in+docs
Del: other reasons-- https://master.php.net/note/delete/87862
Reject -- https://master.php.net/note/reject/87862
Search -- https://master.php.net/manage/user-notes.php