将帖子数据转换为字符串

时间:2016-05-02 20:10:21

标签: php

我正在编写一个将用户输入转换为字符串的php程序,并计算每个字符的使用次数,最终计算每个字。有谁知道如何将帖子数据转换为字符串?我看着implodecount_chars,但内心并没有像预期的那样转换为字符串。我不确定如何显示它遇到的错误以提供更多信息。我正在运行它并在phpFiddle中编写它。我不确定如何在其他地方运行它。请提供有关implode可能出错的信息,如何在phpFiddle中显示错误,或在没有phpFiddle的浏览器中运行此信息。

<?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>

3 个答案:

答案 0 :(得分:5)

这可能就是你要找的...... implode("", $_POST)

答案 1 :(得分:5)

Imploding PHP Arrays通常需要两个参数,分隔符和数组。

要将$ _POST数组转换为字符串,您应该能够使用它进行内爆;

implode('', $_POST);

答案 2 :(得分:1)

我希望这就是你要找的东西。

&#13;
&#13;
<?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>
&#13;
&#13;
&#13;