您当前的位置:首页 > php > php替换换行回车符textarea

php替换换行回车符textarea

日期:2021-08-24 20:38:17    浏览:433

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    echo "<pre>";
    $p = $_POST['text'];
//    $c = explode(chr(13) . chr(10), $p);
    $c = explode("\r\n", $p);
    $c = explode(PHP_EOL, $p);
    $c = array_filter($c);//过滤空数据
//        print_r($c);
//    $res = array_map(function ($item) {
//        //替换回车或者换行符为空
//        return str_replace([chr(13) . chr(10), chr(10), chr(13)], "", $item);
//    }, $c);
    print_r($c);

    echo "</pre>";
}

?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<form action="" method="post" enctype="application/x-www-form-urlencoded">
    <textarea name="text" id="" cols="30" rows="10">a
b
c
d
e
f
g</textarea>
    <button type="submit">提交</button>
</form>
</body>
</html>

Tags: php 数组

世事无常

要有遥不可及的梦想,也要有脚踏实地的本事