SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 23rd, 2002, 10:05 AM
Mustafa Karaoglu Mustafa Karaoglu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Adana - Turkey
Posts: 39 Mustafa Karaoglu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Mustafa Karaoglu Send a message via AIM to Mustafa Karaoglu Send a message via Yahoo to Mustafa Karaoglu
read sentences from a a-bit-long txt file

How can we read a text (let's say a story text, or smthng else ) and put it into a mysql db sentence by sentence, every single sentence will be a line in db.

Reply With Quote
  #2  
Old August 23rd, 2002, 12:32 PM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: read sentences from a a-bit-long txt file

Here's a start.

php Code:
Original - php Code
  1.  
  2. <?
  3.  
  4. $data = file("text.txt");
  5. $data = implode("n", $data);
  6. $data = explode(".", $data);
  7. for ($i=0; $i<count($data); $i++)
  8. {
  9. databasefunc... $data[$i];
  10. }
  11.  
  12. ?>


Know that this is not perfect, but maybe others could work with it...

Reply With Quote
  #3  
Old August 23rd, 2002, 06:29 PM
Mustafa Karaoglu Mustafa Karaoglu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Adana - Turkey
Posts: 39 Mustafa Karaoglu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Mustafa Karaoglu Send a message via AIM to Mustafa Karaoglu Send a message via Yahoo to Mustafa Karaoglu
RE: read sentences from a a-bit-long txt file

I did this it does what I want but deletes dot and question marks at the and of sentence.

$data = file("text.txt");
$data = implode("n", $data);
$data=preg_split ("/[.?]/" , $data, -1, PREG_SPLIT_DELIM_CAPTURE);

how can I correct it not to delete dot

Reply With Quote
  #4  
Old August 23rd, 2002, 06:51 PM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: read sentences from a a-bit-long txt file

You can make a preg_replace(".", ".<dot>", $data);
explode("<dot>", $data);


Reply With Quote
  #5  
Old August 25th, 2002, 12:35 PM
Mustafa Karaoglu Mustafa Karaoglu is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Adana - Turkey
Posts: 39 Mustafa Karaoglu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Mustafa Karaoglu Send a message via AIM to Mustafa Karaoglu Send a message via Yahoo to Mustafa Karaoglu
RE: read sentences from a a-bit-long txt file

I got this error :
No ending delimiter '.' found in ...

and also another problem a sentence may end with ? or !

Reply With Quote
  #6  
Old August 25th, 2002, 08:03 PM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: read sentences from a a-bit-long txt file

Can't test it right at this moment, but try:
preg_replace("'.'", ".<dot>", $data);

I'm not an expert in regular expressions, but if you would like to split at ? and ! I think this will work:

<?
$search = array("'.'", "'?'", "'!'");
$replace = array(".<dot>", ".<dot>", ".<dot>");
preg_replace($search, $replace, $data);


Reply With Quote
  #7  
Old August 25th, 2002, 08:08 PM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: read sentences from a a-bit-long txt file

Sorry... Small mistake

php Code:
Original - php Code
  1.  
  2. <?
  3. $search = array("'.'", "'?'", "'!'");
  4. $replace = array(".<dot>", ".<dot>", ".<dot>");
  5. $preg_replace($search, $replace, $data);
  6. ?>


Maybe others could verify this?

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > read sentences from a a-bit-long txt file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway