Tuesday, January 20, 2009

Split the p tag

<html>
<head>
<meta name="description" content="Split the <p> tag into some numbers" />
<meta name="keywords" content="Split the p tag ,Split the p tag using regular expression,Split the p tag using php " />
</head>
<body>
<?php
$inp = '<p>Paragraph1</p><p>Paragraph2</p><p>Paragraph3</p><p>Paragraph4</p><p>Paragraph5</p><p>Paragraph6</p>';
$expression = '/<p>(.*)<\/p>/';
preg_match_all($expression,$inp,$match);
$match = explode("</p><p>",$match[1][0]);
for($i=0;$i<2;$i++){
echo '<p>'.$match[$i].'</p>';
}
echo '=======================';
for($i=0;$i<count($match);$i++){
echo '<p>'.$match[$i].'</p>';
}
?>
</body>
</html>

No comments:

Post a Comment