dongmo20030416 2012-03-14 23:58
浏览 24
已采纳

删除降价格式以便快速摘录

Anyone know of a script or already built function that will help me create a quick excerpt using already existing markdown formatted content?

I am looking at formatting results like StackOverflow where I have the title, and a short excerpt, for basically news view. I want to remove the markdown fully and just preserve the few words.

My concern is that I am going to use a codeigniter helper word_limiter()to limit the output. Which may create broken markdown:

**This is a sentence which has some _markdown_ that is [cutoff..

So I'm not sure how to go about it.

All my content is stored with markdown (not HTML formatting) otherwise I would do 'striptags' etc;

I've found something similar for Ruby on SO here: Truncate Markdown?, but I would love something for PHP.

I'm just not sure if I should just strip all *_[]()> characters basically? But if there is a URL (split in half), I'm worried it will look nasty.

Thoughts? I've looked around a bit, but at first glance haven't found anything that strips markdown.

  • 写回答

1条回答 默认 最新

  • dongmei8760 2012-03-15 00:02
    关注

    Consider marking-up the text, then running strip_tags.

    -- Update --

    There are a couple of other options, if you do not want to mark-up the text just to strip tags, you can:

    1. Introduce a regex to strip out the markdown elements

    2. Store the content in the database with NO markup/markdown, just the text

    3. If you mark-up then strip_tags, you can store the results in memcache to avoid the extra overhead

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!