dqsong2010 2015-10-08 11:14
浏览 47

由于结束括号,PHP substr()混乱样式

Scenario :

  1. I have used a text editor to input my large content ( Wordpress ).
  2. So, now the content is to be displayed at homepage so i use the php queries to display the content.

  3. Now, i need the content to be in a size of 100-200 so i have used substr() function of php in order to do so.

  4. Also, i need the content to be displayed with different html tags involved in my homepage.

Function Code:

$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>'; 
}

Output Code:

<?php echo cstom_function_excerpt(100); ?>

So the above code o/p's the contents correctly but the content breaks my other div's and styles becasuse due to substr() function the html tags are not being properly closed.

So, my question is how do i solve this issue of self closing the html tags when i use the substr() function so that my style's and layout does not end of messing ??

I have searched this issue but failed to achieve any related and good answer. So, please help me to solve this issue.. !!

Thanx

  • 写回答

1条回答 默认 最新

  • dongshanni1611 2015-10-08 13:53
    关注

    try

    $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>'; 
    
    
    
    }
    

    Hope this help.

    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000