php – 计算已发布字符串中的行数
发布时间:2020-12-13 13:11:41 所属栏目:PHP教程 来源:网络整理
导读:我试过这个: count new lines in textarea to resize container in PHP? 但它似乎没有起作用: $content = nl2br($_POST['text']);preg_match_all("/(br)/",$content,$matches);echo count($matches[0]) + 1; 它总是输出1. 有没有其他解决方案来计算字符串
我试过这个:
count new lines in textarea to resize container in PHP?
但它似乎没有起作用: $content = nl2br($_POST['text']); preg_match_all("/(<br>)/",$content,$matches); echo count($matches[0]) + 1; 它总是输出1. 有没有其他解决方案来计算字符串中的行?
在我的一个旧应用程序中找到了这个…不知道我从哪里得到它.
$lines_arr = preg_split('/n|r/',$str); $num_newlines = count($lines_arr); echo $num_newlines; *编辑 – 实际上,如果你的textarea正在吐出html,这可能不会起作用..检查< br>和< br /> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |