Posted By

hasantayyar on 07/31/09


php regular Expression pregmatch

Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


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

 / Published in: PHP


"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."

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

Report this snippet  

You need to login to post a comment.