剪切HTML内容并保持格式?

时间:2011-06-10 12:24:20

标签: php

$str = "<div>blahblahblah<b>foofoo</b><i>barbar</i></div>";

我将两部分分开

1-presentation_text
2-full content when click on read more.

  $presentation  = substr($str,0,23);
 <div>blahblahblah<b>foo
  $detail = substr($str,23); 
  foo</b><i>barbar</i></div>

如何在演示文稿块和详细信息块中显示格式? 我的意思是

表示块中的

应为:

blahblahblah foo / * foo在这里加粗* /



详细信息块

foo barbar / * foo也加粗* /

1 个答案:

答案 0 :(得分:1)

客户端更容易做到:

CSS

.presentation {
    width: 200px;
    height: 20px;
    overflow: hidden;
}
.detail {
    width: auto;
    height: auto;
}

的Javascript

$(function(){
    $('.presentation').live('click', function(){
        $(this).attr('class', 'detail');
    });

    $('.detail').live('click', function(){
        $(this).attr('class', 'presentation');
    });
});

HTML

<div class="presentation">
    <div>blahblahblah<b>foofoo</b><i>barbar</i></div>
</div>

工作示例:http://jsfiddle.net/fznWf/1/