Results 1 to 13 of 13
  1. #1
    In The Zone bukaida's Avatar
    Join Date
    Jul 2005
    Location
    KOLKATA
    Posts
    274

    Default PHP Help me extract page number from text

    The document is inserted as a text file in the database. the table structure is

    id(number) Title(Text) Body(Long Text)

    The body may be a 500 page book in text format.

    The content in the text file is written (continuously) as

    -(-p- 1 )-

    content of page 1

    -(-p- 2 )-

    content of page 2

    ---so on

    Now I need to store this data as individual page in another table automatically which has the following structure--

    id ( may be FK from previous table)
    content (page wise text content, automatically extracted)
    page number( automatically extracted)

    I am in total blank how to generate the second table from the first one. I am using PHP 5 with Mysql 5 and Apache 2.2.
    Any suggestion is gracefully accepted.

    P.S-- The actual page numbers are unicode non-english numbers which are unique and never repeated inside the body of the text.
    Desktop: P-IV 2.4GHz, 512MB DDR, 865GBF Mother Board,
    G-Force 5200FX, 17" Samsung flat, WinXp with SP2,
    Kaspersky Internet Security 2012.
    Laptop:LENOVO 3000 C100 D7 lappy with 2GB DDR2.

  2. #2
    Alpha Geek cute.bandar's Avatar
    Join Date
    Jan 2010
    Posts
    528

    Default Re: PHP Help me extract page number from text

    maybe have a look at querypath OR preg_match OR simple_html_dom ?

    I think, but am not sure, that using preg_match would solve your issue. Check its manual page and report back if you need more help..

  3. #3
    In The Zone bukaida's Avatar
    Join Date
    Jul 2005
    Location
    KOLKATA
    Posts
    274

    Default Re: PHP Help me extract page number from text

    Quote Originally Posted by cute.bandar View Post
    maybe have a look at querypath OR preg_match OR simple_html_dom ?

    I think, but am not sure, that using preg_match would solve your issue. Check its manual page and report back if you need more help..
    I have to extract the text between the two page numbers and assign the smaller page number (between the two) to the extracted page and insert them to the table immediately. This process continues until the end of the file is reached. I cannot use a counter to generate page number as the book contains index pages and references also which does not have any page number.

    P.S- I think querypath cannot be used with plain text, it can be used only with html or XML. Not sure though.
    Last edited by bukaida; 13-06-2012 at 11:24 PM. Reason: Remember more later
    Desktop: P-IV 2.4GHz, 512MB DDR, 865GBF Mother Board,
    G-Force 5200FX, 17" Samsung flat, WinXp with SP2,
    Kaspersky Internet Security 2012.
    Laptop:LENOVO 3000 C100 D7 lappy with 2GB DDR2.

  4. #4
    Alpha Geek cute.bandar's Avatar
    Join Date
    Jan 2010
    Posts
    528

    Default Re: PHP Help me extract page number from text

    hmm
    then maybe you could look for double/triple linebreaks or something. Just thinking... Its difficult for me to say conclusively without seeing a sample of the data.

  5. #5
    Master KOD3R nbaztec's Avatar
    Join Date
    Sep 2010
    Location
    New Delhi
    Posts
    342

    Default Re: PHP Help me extract page number from text

    Use
    PHP Code:
          $pages preg_split('/-(-p- \d+ )-/'$body);
          foreach(
    $pages as $i=>$p)
               echo 
    "Page no: $i""Body: $p"
    AMD Phenom II X6 1055T|MSI 880GMA-E45|MSI 7770|2x2 Corsair DDR3 1333MHz|CM Elite 310|Corsair CX400W|DELL ST2320L
    Myself @ nbaztec.co.in
    Build Your Rig! (XBlade) @ nbaztec.co.in - Build Your Rig!
    My Inner Artist @ nbaztec.co.in - Designs

  6. #6
    change is constant!! khmadhu's Avatar
    Join Date
    Jan 2010
    Location
    Bengaluru
    Posts
    496

    Default Re: PHP Help me extract page number from text

    ^
    @nbaztec you need to escape '(' and '-' characters.

    so
    PHP Code:
     /-(-p- \d+ )-/ 
    becomes
    PHP Code:
       /\-\(\-p\- \d+ \)\-/ 
    Last edited by khmadhu; 14-06-2012 at 05:46 PM. Reason: added PHP tag
    If you really wanna think, try to think from Atom to Universe!!

    cpu: core i5 2500k, mobo: DP67BG, RAM:Corsair 8GB(4x2) 1600 Mhz, XFX HD 5770, 1TB seagate 6Gbps 7200 rpm , SAGA II 500W

  7. #7
    Master KOD3R nbaztec's Avatar
    Join Date
    Sep 2010
    Location
    New Delhi
    Posts
    342

    Default Re: PHP Help me extract page number from text

    Quote Originally Posted by khmadhu View Post
    ^
    @nbaztec you need to escape '(' and '-' characters.

    so
    PHP Code:
     /-(-p- \d+ )-/ 
    becomes
    PHP Code:
       /\-\(\-p\- \d+ \)\-/ 
    No only the '(' which I missed since I copied OP's string directly.
    AMD Phenom II X6 1055T|MSI 880GMA-E45|MSI 7770|2x2 Corsair DDR3 1333MHz|CM Elite 310|Corsair CX400W|DELL ST2320L
    Myself @ nbaztec.co.in
    Build Your Rig! (XBlade) @ nbaztec.co.in - Build Your Rig!
    My Inner Artist @ nbaztec.co.in - Designs

  8. #8
    change is constant!! khmadhu's Avatar
    Join Date
    Jan 2010
    Location
    Bengaluru
    Posts
    496

    Default Re: PHP Help me extract page number from text

    I thought '-' may interfere with range symbol, I think it depends on regex engine!.
    If you really wanna think, try to think from Atom to Universe!!

    cpu: core i5 2500k, mobo: DP67BG, RAM:Corsair 8GB(4x2) 1600 Mhz, XFX HD 5770, 1TB seagate 6Gbps 7200 rpm , SAGA II 500W

  9. #9
    Master KOD3R nbaztec's Avatar
    Join Date
    Sep 2010
    Location
    New Delhi
    Posts
    342

    Default Re: PHP Help me extract page number from text

    No, '-' has meaning only inside character classes. It's valid across all common regex engines.
    AMD Phenom II X6 1055T|MSI 880GMA-E45|MSI 7770|2x2 Corsair DDR3 1333MHz|CM Elite 310|Corsair CX400W|DELL ST2320L
    Myself @ nbaztec.co.in
    Build Your Rig! (XBlade) @ nbaztec.co.in - Build Your Rig!
    My Inner Artist @ nbaztec.co.in - Designs

  10. #10
    In The Zone bukaida's Avatar
    Join Date
    Jul 2005
    Location
    KOLKATA
    Posts
    274

    Default Re: PHP Help me extract page number from text

    Ok guys, here is the sample data
    Code:
    -(-পৃ- ৩৭৮ )-
    
    গোরা
    
    
    -(-পৃ- ৩৭৯)-
    ১  
    শ্রাবণ মাসের সকালবেলায় মেঘ কাটিয়া গিয়া নির্মল রৌদ্রে কলিকাতার আকাশ ভরিয়া গিয়াছে। রাস্তায় গাড়িঘোড়ার বিরাম নাই, ফেরিওয়ালা অবিশ্রাম হাঁকিয়া চলিয়াছে, যাহারা আপিসে কালেজে আদালতে যাইবে তাহাদের জন্য বাসায় বাসায় মাছ-তরকারির চুপড়ি আসিয়াছে ও রান্নাঘরে উনান জ্বালাইবার ধোঁওয়া উঠিয়াছে কিন্তু তবু এত বড়ো এই-যে কাজের শহর কঠিনহৃদয় কলিকাতা, ইহার শত শত রাস্তা এবং গলির ভিতরে সোনার আলোকের ধারা আজ যেন একটা অপূর্ব যৌবনের প্রবাহ বহিয়া লইয়া চলিয়াছে। 
    এমন দিনে বিনা-কাজের অবকাশে বিনয়ভূষণ তাহার বাসার দোতলার বারান্দায় একলা দাঁড়াইয়া রাস্তায় জনতার চলাচল দেখিতেছিল। কালেজের পড়াও অনেক দিন চুকিয়া গেছে, অথচ সংসারের মধ্যেও প্রবেশ করে নাই, বিনয়ের অবস্থাটা এইরূপ। সভাসমিতি চালানো এবং খবরের কাগজ লেখায় মন দিয়াছে— কিন্তু তাহাতে সব মনটা ভরিয়া উঠে নাই। অন্তত আজ সকালবেলায় কী করিবে তাহা ভাবিয়া না পাইয়া তাহার মনটা চঞ্চল হইয়া উঠিতেছিল। পাশের বাড়ির ছাতের উপরে গোটা-তিনেক কাক কী লইয়া ডাকাডাকি করিতেছিল এবং চড়ুই-দম্পতি তাহার বারান্দার এক কোণে বাসা-নির্মাণ-ব্যাপারে পরস্পরকে কিচিমিচি শব্দে উত্সাহ দিতেছিল— সেই-সমস্ত অব্যক্ত কাকলি বিনয়ের ইচ্ছা করিতে লাগিল বাউলকে ডাকিয়া এই অচিন পাখির গানটা লিখিয়া লয়, কিন্তু ভোর-রাত্রে যেমন শীত-শীত করে অথচ গায়ের কাপড়টা টানিয়া লইতে উদ্যম থাকে না, তেমনি একটা আলস্যের ভাবে বাউলকে ডাকা হইল না, গান লেখাও হইল না, কেবল ঐ অচেনা পাখির সুরটা মনের মধ্যে গুন্* গুন্* করিতে লাগিল। 
    বিনয় তাঁহাকে ধরাধরি করিয়া নামাইয়া দিল, এবং তাঁহার মুখ বিবর্ণ হইয়া গেছে দেখিয়া জিজ্ঞাসা করিল, “আপনার লাগে নি তো?” 
    তিনি “না, কিছু হয় নি” বলিয়া হাসিবার চেষ্টা করিলেন, সে হাসি তখনই মিলাইয়া গেল এবং তিনি মূর্ছিত হইয়া পড়িবার উপক্রম করিলেন। বিনয় তাঁহাকে ধরিয়া ফেলিল ও উত্কণ্ঠিত মেয়েটিকে কহিল, “এই সামনেই আমার বাড়ি ; ভিতরে চলুন।” 
    বৃদ্ধকে বিছানায় শোওয়ানো হইলে মেয়েটি চারি দিকে তাকাইয়া দেখিল ঘরের কোণে একটি জলের কুঁজা আছে। তখনই সেই কুঁজার জল গেলাসে করিয়া লইয়া বৃদ্ধের মুখে ছিটা দিয়া বাতাস 
    -(-পৃ- ৩৮০)-
    Donot bother much about the content ( A text in bengali from tagore, you can copy-paste to google translate if you are really interested )

    The interesting terms are -(-পৃ- ৩৭৮ )- and -(-পৃ- ৩৭৯)- from where only the ৩৭৮ and ৩৭৯ are page numbers. The aim is to extract the content between this two and assign ৩৭৮ to it since it appeared earlier ( cannot do comparison to find the smaller directly, I think).
    Desktop: P-IV 2.4GHz, 512MB DDR, 865GBF Mother Board,
    G-Force 5200FX, 17" Samsung flat, WinXp with SP2,
    Kaspersky Internet Security 2012.
    Laptop:LENOVO 3000 C100 D7 lappy with 2GB DDR2.

  11. #11
    Master KOD3R nbaztec's Avatar
    Join Date
    Sep 2010
    Location
    New Delhi
    Posts
    342

    Default Re: PHP Help me extract page number from text

    The thing is regex engines don't support UTF-8. But they support Unicode. So you'll have to form the regex manually while knowing the unicode codes for the characters.

    For eg:

    PHP Code:
    $pages preg_split('/-\s*\(\s*-\s*\x{09aa}\x{09c3}\s*-\s*([\x{09e6}-\x{09ef}]+)\s*\)-\)-/u'$s)); 
    The regex can be used to split on those lines and also to obtain the page numbers. Alternatively the indexes of the pages are themselves page numbers.
    AMD Phenom II X6 1055T|MSI 880GMA-E45|MSI 7770|2x2 Corsair DDR3 1333MHz|CM Elite 310|Corsair CX400W|DELL ST2320L
    Myself @ nbaztec.co.in
    Build Your Rig! (XBlade) @ nbaztec.co.in - Build Your Rig!
    My Inner Artist @ nbaztec.co.in - Designs

  12. #12
    In The Zone bukaida's Avatar
    Join Date
    Jul 2005
    Location
    KOLKATA
    Posts
    274

    Default Re: PHP Help me extract page number from text

    Quote Originally Posted by nbaztec View Post
    The thing is regex engines don't support UTF-8. But they support Unicode.
    Alternatively the indexes of the pages are themselves page numbers.
    The original document is in unicode only. However, since mysql supports utf8 not unicode, I had to convert it to utf8.

    The pages are not continuous. So index cannot be used.
    Desktop: P-IV 2.4GHz, 512MB DDR, 865GBF Mother Board,
    G-Force 5200FX, 17" Samsung flat, WinXp with SP2,
    Kaspersky Internet Security 2012.
    Laptop:LENOVO 3000 C100 D7 lappy with 2GB DDR2.

  13. #13
    Master KOD3R nbaztec's Avatar
    Join Date
    Sep 2010
    Location
    New Delhi
    Posts
    342

    Default Re: PHP Help me extract page number from text

    Quote Originally Posted by bukaida View Post
    The original document is in unicode only. However, since mysql supports utf8 not unicode, I had to convert it to utf8.

    The pages are not continuous. So index cannot be used.
    Then finding out the unicode values shouldn't be a problem for you. As for the page numbers, the same expression can obtain the page number through preg_match() and will be group 1 or $match[1].
    AMD Phenom II X6 1055T|MSI 880GMA-E45|MSI 7770|2x2 Corsair DDR3 1333MHz|CM Elite 310|Corsair CX400W|DELL ST2320L
    Myself @ nbaztec.co.in
    Build Your Rig! (XBlade) @ nbaztec.co.in - Build Your Rig!
    My Inner Artist @ nbaztec.co.in - Designs

Similar Threads

  1. pass a text information to a php page using link
    By bukaida in forum Programming
    Replies: 4
    Last Post: 27-05-2008, 11:55 AM
  2. How to convet scanned page. into text format
    By Kaushal Hiwarkar in forum QnA (read only)
    Replies: 3
    Last Post: 22-10-2007, 03:23 PM
  3. MS Word Auto Page Number Problem
    By khandu in forum Software Q&A
    Replies: 1
    Last Post: 30-03-2007, 12:46 AM
  4. IS it possible to extract text from BMP/JPEG image..?
    By mkmkmk in forum QnA (read only)
    Replies: 10
    Last Post: 31-05-2006, 07:10 PM
  5. printed page back to text file...?
    By Saharika in forum QnA (read only)
    Replies: 2
    Last Post: 13-11-2005, 06:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Close