Split Text read from a Text file into paragraphs using php

Posted by admin on 31st, 2007

How to read/convert the data read from a text file into paragraphs and display them paragraph wise.  I did a lot of searching about this issue to achieve success. So it thought of just publishing that part of how to split the data paragraph wise and then displaying it.

preg_match_all(‘~ <p>.*?</p>~s’, $rawdata,$m);
 $paragraphs = $m[0];
foreach($paragraphs as $p)
 { echo $p; }

Here $rawdata is the source in which the preg_replace will search for the pattern <p> </p> and the data between the paragraph tags will be given to $m(array)

$m[0] gives the first  matches ie all the paragraphs in the data to $paragraphs(another array). Using the Loop we can now display Paragraphs one by one.

Note: This is my first time im explaining a script. Please excuse me. I’ll work out more to learn more n explaing more :)

Be Sociable, Share!
If you enjoyed this post, make sure you subscribe to my RSS feed!

Related Posts