truncatechars
過濾器可以對字符串進行截取并添加…,該方法會截斷單詞,指定長度包括…。
truncatechars_html
過濾器可以對html代碼進行截取并添加…,該方法會截斷單詞,指定長度包括…。
truncatewords
過濾器可以對字符串按單詞進行截取并添加…。
truncatewords_html
過濾器可以對html代碼按單詞進行截取并添加…。
truncatechars
過濾器的使用方法:
}
truncatechars_html
過濾器的使用方法:
}
truncatewords
過濾器的使用方法:
}
truncatewords_html
過濾器的使用方法:
}
比如需要將 Joel is a slug
截取9個字符,多出部分使用…代替,則可以這么寫:
}顯示結(jié)果
Joel i…
truncatechars
過濾器
} } } } }顯示結(jié)果
Joel i… Joel is a … Joel is a slug 你 你好
truncatewords
過濾器
} } }
顯示結(jié)果
Lorem ipsum dolor sit amet, consectetur adipisici elit, sed … 10
你好世界 你好世界
truncatechars_html
過濾器
} } } } } }顯示結(jié)果
This is a long test wh… <div class=“foo”><ul class=“foo”><li class=“foo”><p class=“foo”>This is a long test wh…</p></li></ul></div> <p class=‘test’ id=‘foo’>This is a long test wh…</p> <a name=‘link’><p>This </a>is a long test wh…</p> <p>This </a>is a long test wh…</p> <p>This…</p>
truncatewords_html
過濾器
} } } } } } }顯示結(jié)果
This is a long test which will be cutted after some words. <div class=“foo”><ul class=“foo”><li class=“foo”><p class=“foo”>This is a long test …</p></li></ul></div> <p>This. is. a. long test. Test test, test….</p> <a name=‘link’ href=“https://….”><p class=“foo”>This </a>is a long test,…</p> <p>This </a>is a long test,…</p> <p>This is …</p>