kin*_*juf 38 php string newline strstr
在PHP 5.3中有一个很好的功能,似乎做我想要的:
strstr(input,"\n",true)
Run Code Online (Sandbox Code Playgroud)
不幸的是,服务器运行PHP 5.2.17并且可选的第三个参数strstr
不可用.有没有办法在以前的版本中实现这一点?
You*_*nse 100
干得好
$str = strtok($input, "\n");
Run Code Online (Sandbox Code Playgroud)
Con*_*ney 10
现在已经晚了,但你可以使用爆炸.
<?php
$lines=explode("\n", $string);
echo $lines['0'];
?>
Run Code Online (Sandbox Code Playgroud)
$first_line = substr($fulltext, 0, strpos($fulltext, "\n"));
Run Code Online (Sandbox Code Playgroud)
或其他什么东西可以解决问题.丑陋,但可行.