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 :)

Tags :No Tags

If you Like this post buy me a Coffee

Popularity: 8% [?]

Related Posts

  • My First earning as a Rent a Coder
  • Websites to Flip or Type Upside Down
  • File your Income Tax (IT) returns Online at myitreturn.com
  • Adsense Alternative publisher programs Part 1
  • How to Print only selections

  • Leave a Reply