gpt4 book ai didi

javascript - 由于右括号导致 PHP substr() 风格困惑

转载 作者:行者123 更新时间:2023-11-28 06:50:17 25 4
gpt4 key购买 nike

场景:

  1. 我使用文本编辑器输入大量内容 (Wordpress)。
  2. 所以,现在内容要显示在主页上,所以我使用 php 查询来显示内容。

  3. 现在,我需要内容的大小为 100-200,因此我使用了 php 的 substr() 函数来实现此目的。

  4. 此外,我需要使用主页中涉及的不同 html 标签来显示内容。

功能代码:

$text = get_field('independent_excerpt', $post->ID);
if (strlen($text) > $length) {
$text = substr($text,0,strpos($text,' ',$length)) . '<a class="link_custom_evidenz" href="' . get_permalink() . '">[Leggi Tutto]</a>';
}

输出代码:

<?php echo cstom_function_excerpt(100); ?>

所以上面的代码 o/p 的内容正确,但内容破坏了我的其他 div 和样式,因为由于 substr() 函数,html 标签没有正确关闭。

所以,我的问题是,当我使用 substr() 函数时,如何解决自动关闭 html 标签的问题,这样我的样式和布局就不会结束困惑??

我已经搜索过这个问题,但未能获得任何相关且好的答案。所以,请帮我解决这个问题..!!

谢谢

最佳答案

尝试

$text = get_field('independent_excerpt', $post->ID);
if (strlen($text) > $length) {
$text = substr($text,0,strpos($text,' ',$length));
$text = html_entity_decode($text);
$text = str_replace("'", '`', $text);

$text. '<a class="link_custom_evidenz" href="' . get_permalink() . '">[Leggi Tutto]</a>';



}

希望这有帮助。

关于javascript - 由于右括号导致 PHP substr() 风格困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com