我正在编写一个php程序,该程序将用户输入转换为字符串,并计算每个字符的使用次数,最终计算每个单词的使用次数。有人知道如何将帖子数据转换为字符串吗?我看到了内爆和count_chars,但内爆并没有像预期的那样转换为字符串。我不知道如何显示它遇到的错误以提供更多信息。我正在运行它并用phpFiddle编写它。我不知道如何在其他地方运行它。请提供关于内爆可能有什么问题的信息,如何在phpFiddle中显示错误,或者在没有phpFiddl的浏览器中运行它。
<?php
echo $_POST['value'];
$post_string = implode($_POST);
foreach (count_chars($post_string, 1) as $i => $val) {
echo "there were $val instances of '"", chr($i) , "'" in the string. 'n";
}
?>
<form method="post" action="">
<input type="text" name="value">
<input type="submit">
</form>
这可能就是您想要的。。。。implode("", $_POST)
隐含PHP数组通常需要两个参数,分隔符和数组。
要将$_POST数组转换为字符串,您应该能够使用;
implode('', $_POST);
我希望这就是您想要的。
<?php
if (isset ($_POST['value'])) {
echo $_POST['value'] . "<br>";
}
$post_string = implode("", $_POST);
foreach (count_chars($post_string, 1) as $i => $val) {
echo "There were $val instances of '"", chr($i) , "'" in the string. <br>";
}
?>
<form method="post" action="">
<input type="text" name="value">
<input type="submit">
</form>