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

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

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件