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

Popularity: 4% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
If you enjoyed this post, make sure you subscribe to my RSS feed!

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
  • Restore Show Desktop Icon to Quick Launch on Taskbar

  • 4 Responses to “Split Text read from a Text file into paragraphs using php”

    1. poer

      hi, thanks for the code, it’s really help me with my project.


    2. USED CARS KERALA

      thaank you.. u helped me to write about me in ma website


    3. e!

      wtc


    4. head

      http://fatcowwebhosting143.wordpress.com/2011/09/05/the-art-of-investing-income-when-in-college-on-a-shoestring/


    Leave a Reply



    Search


    SUBSCRIBE

    SPONSORS

    sidebanner sidebanner sidebanner