在PHP中显示更多并显示更少(无JavaScript)

时间:2016-10-12 07:24:14

标签: php php-5.2

在这里我 <form action="<%=request.getContextPath()%>/appLogout" method="POST"> <input type="submit" value="Logout"/> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> </form> ,我从中得到了一个段落。我想只显示50个单词。之后,我想显示更多链接,点击后,我想显示剩余的单词加上显示更少的按钮。点击显示较少的链接意味着我只想再显示50个单词。我怎么能这样做?

echo $description

1 个答案:

答案 0 :(得分:0)

编辑问题以提供一个页面解决方案,抱歉也发现了以前版本中的错误

onepagetext.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
$full_string= 'Initially when my view loads, it should display the first question and answer. When press the next button I need to pass next value to the model and get the second question and answer, and if next button is clicked again it should display the third question and answer. The next button should be clickable until the last question appears. I have the following code:';

$legend = 'Show less';
$length= 'long';
if (isset($_POST['formsubmitted'])) {   
    if ($_POST["length"] == 'short'){   
    echo $full_string;  
    $length = 'long';
    $legend = 'Show less';
    }
    if ($_POST["length"] == 'long'){
        //echo $full_string;
        $full_string_array = explode(' ', $full_string);
        $short_string_array = array_slice($full_string_array, 0, 10);
        $short_string = implode($short_string_array,' ');
        echo $short_string;         
        $length = 'short';
        $legend = 'Show more';
    }
}
else {
echo $full_string;  
}
?>
<form name="new user" method="post" action="onepagetext.php"> 
<input type="hidden" name="formsubmitted" value="TRUE">
<input type="hidden" name="length" value="<?php echo $length;?>">
<input type="submit"  value="<?php echo $legend;?>">
</form>
</body>
</html>