PHP: remove anchors and other tags from the intro with regular expression


/ Published in: PHP
Save to your folder(s)

"Recently I was playing around with WordPress’ wp_posts table. I wanted to grab the basic information about my posts (ID, title, content, slug) and build a quick summary list of them. One problem I ran into was creating a content “intro.” Luckily a quick regular expression allowed me to create the intro."


Copy this code and paste it in your HTML
  1. preg_match("/<p>(.*)<\/p>/",$post['post_content'],$matches);
  2. $intro = strip_tags($matches[1]); //removes anchors and other tags from the intro

URL: http://davidwalsh.name/php-paragraph-regular-expression

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.