好的,伙计们,这个问题与我上一个问题有关。
如果我设置了 $textlimit = 500; 这会将我的文本限制为 500 个字符。
有没有办法“避免”文本限制,然后 onclick 函数加载其余部分?
例如,如果我设置:
$textpart = substr($fulltext, 0, 400);
$textpart 将仅包含 400 个字符的字符串。
我的问题是,如何声明变量,该变量将包含长度超过 500 个字符的文本的其余部分?
变量示例:
$fulltext //Contains full text, but is limited to 500 characters.
$textpart //Contains part of the text, substr 400 characters out of 500.
$textrest //This variable to "hold" rest of the text, after 400 characters of $textpart.
就像我在上一个问题中所问的那样,我想制作展开和折叠按钮,我现在知道如何做到这一点,但我不知道如何划分文本。
表单将如下所示:
- 这里随机文本(400 个字符长)
- 用于展开的随机图像
- 声明 onclick 函数 I 后,加载文本的其余部分(超过 500 个字符)。
- 用于崩溃的随机图像
- 在声明 onclick 函数崩溃并返回到之前的状态之后 - 引文 1.
我希望我以正确的方式解释了我的问题。我真的很感激任何类型的帮助,如果我可以选择,我只想了解如何做到这一点的基本解释,因为我想学习这一点,而不是复制/粘贴解决方案(它更容易,但我不会学到太多)。
提前致谢。
Ok guys, this question is related to my previous one.
If I have set $textlimit = 500; that will limit my text to 500 characters.
Is there any way to "avoid" text limit, and then onclick function load rest of it?
For example, if I set:
$textpart = substr($fulltext, 0, 400);
$textpart will only contain 400 characters of string.
My question is, how to declare variable, which will contain the rest of the text which is much longer than 500 characters?
Example of variables:
$fulltext //Contains full text, but is limited to 500 characters.
$textpart //Contains part of the text, substr 400 characters out of 500.
$textrest //This variable to "hold" rest of the text, after 400 characters of $textpart.
Like I've asked in previous question, I wanted to make expand and collapse button, I now know how to do that, but I don't know how to divide text.
Form would go like this:
- Random text here(400 characters long)
- Random image for expand
- After declared onclick function I, load rest of the text (Over 500 characters).
- Random image for collapse
- After declared onclick function collapse and return to previous state - citation 1.
I hope I explained my question the right way. I would really appreciate any kind of help, if I can choose, I would like just basic explanation on how to that, because I want to learn that, not copy/paste solution (it is easier, but I will not learn much).
Thanks in advance.
发布评论
评论(3)
如果我理解正确,您希望向用户显示一个仅显示前 X 个字符的初始页面,然后在用户单击文本时显示所有字符。
有三种策略可以做到这一点。从简单到困难:
选项 2 和 3 需要使用客户端 JavaScript,因此不是纯 PHP 解决方案。
选项 1 是将
$_GET
变量(例如?expand=para1
)添加到您的 url 中,并扩展 PHP 中通过$_GET[' 标识的文本展开']
。不要错误地认为 PHP 仍在浏览器的页面上运行。只有 JavaScript 可以在浏览器中运行网页。 (我知道这并不完全正确,但在现实中足够真实。)
If I understand you correctly you want to show the user an initial page that shows only the first X characters and then show all the characters when the users clicks on the text.
There are three strategies to do this. From easy to hard:
Options 2 and 3 require the use of client side JavaScript and are therefore not pure PHP solutions.
Option 1 is a matter of adding a
$_GET
variable, e.g.?expand=para1
, to your url and expanding the text identified in PHP by$_GET['expand']
.Do not make the mistake of thinking PHP is still running on the page in the browser. Only JavaScript can run in the browser on the web page. (Not strictly true I know, but true enough in reality.)