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:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 26th, 2002, 12:27 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
regexp

How can I write a regexp to find sentences between quotation marks in a text file. I want to search a text file and find all sentences between "

Reply With Quote
  #2  
Old August 26th, 2002, 09:36 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: regexp

i know this doesn't directly address your question and it's a bit more complex than the strstr idea but, maybe this will work? : not tested.
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. // new code below :P
  5.  
  6. ?>

Reply With Quote
  #3  
Old August 26th, 2002, 11:28 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: regexp

Hi notepad,
your code prints all quotation marks. But what I need is not the quotation itself. I want the sentences between quotation marks to be printed line by line.

Reply With Quote
  #4  
Old August 26th, 2002, 11:48 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: regexp

whoops, i'll have to debug it when i get home. expect a working example this evening

Reply With Quote
  #5  
Old August 27th, 2002, 03:19 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: regexp

ahhh here we are
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. $file = "myFile.txt";
  5. $contents = file($file);
  6. $fsize = filesize($file);
  7.  
  8. foreach($contents as $value)
  9. {
  10.     $string .= "$value";
  11. }
  12.  
  13. for($i=0; $i<$fsize; $i++)
  14. {
  15.     if($string{$i} == '"')
  16.     {
  17.         $mark[] = $i;
  18.     }
  19. }
  20.  
  21. if(!is_int(count($mark) / 2))
  22. {
  23.     echo "<b>error:</b> there are not an even amount of quotes<br>n";
  24.     exit();
  25. }
  26. else
  27. {
  28.     for($n=0; $n<count($mark); $n++)
  29.     {
  30.         $next = $mark[$n] + 1;
  31.         while($mark[$n] < $mark[($n+1)])
  32.         {
  33.             $quotes[$n] .= $string{$next};
  34.             $next++;
  35.             $mark[$n] = $next;
  36.         }
  37.         $n++;
  38.     }
  39. }
  40.  
  41. print("<b>Here are your quotes:</b><br>");
  42. foreach($quotes as $value)
  43. {
  44.     print("$value<br>n");
  45. }
  46.  
  47. ?>

Reply With Quote
  #6  
Old August 28th, 2002, 01:00 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: regexp

this is pretty fun to play with ..at least i think so

Reply With Quote
  #7  
Old August 28th, 2002, 01:36 AM
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: regexp

What about '"(.*)"' where $1 is the sentence between " " ?

This is just on top of my head - havent testet it or something...



Reply With Quote
  #8  
Old August 28th, 2002, 01:40 AM
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: regexp

Sorry... Think it should be: '"(.*?)"'

Reply With Quote
  #9  
Old August 28th, 2002, 01:44 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: regexp

yah if you can shorten the code to an actual regular expression.. my code suddenly doesn't seem so impressive

Reply With Quote
  #10  
Old August 28th, 2002, 01:54 AM
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: regexp

Sorry... Maybe it doesn't work

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > regexp


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 |