Posted By

hasantayyar on 07/31/09


Tagged

php regular Expression pregmatch


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

vali29
irishsk
umang_nine


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


 / Published in: PHP
 

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

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