473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Extracting a paragraph

Claus Mygind
571 512MB
I have this very poorly written code which will extract the first paragraph after a specified marker. I would like to see a better written code snippert which will do the same thing, perhaps using a regExp (which I do not understand all that well).

Known parameters:

1) the paragraph will start after a string of dashes
"---------------------------------------------"

2) there will be a hard return after the string of dashes

3) each paragraph will end with a hard return which you may identify with chr(10).

The following code works, but surely there is a better way to write this:
Expand|Select|Wrap|Line Numbers
  1. //find start of dashes
  2. $sDash = strpos(trim($c["NOTES"]) , "-----");
  3. //find end of dashes
  4. $eDash = strrpos(trim($c["NOTES"]) , "-----");
  5. //what is the length of the dashes
  6. $lDash = $eDash-$sDash;
  7. //find start position of the first paragraph after dashes
  8. $sPara = substr ( trim($c["NOTES"]) , $eDash+5);
  9. //find the length of the first paragraph by finding the 2nd hard return 
  10. $ePara = strpos ($sPara , chr(10),2);
  11. //paragraph extracted
  12. $cPara = substr ($sPara,0,$ePara);
  13.  
Here is some sample text starting with the word Noten.


Note: Kim is Mike XXXXXX assistant.

--------------------------------------------------------------------------------
03/07/11 - Greg XXXXXX won the 10th door prize at the Open House. klk

03/04/11 - Greg XXXXXXX attended the Open House. klk

11/11/10 - Michael XXXXXX was removed by MVM / kaw
02/09/10 - Laura XXXXX got married. Her new name is Laura XXXXXX. MDB/klk

03/06/09 - Sherwin XXXX won a prize at the Open House. klk

09/26/2008 - Attended CBBEL's reception at the Ill XXXXXXX at Chicago Hilton. Was able to visit with many people from this firm including Chris, Jason, John, John and many more. Everyone was having a good time and I thanked them all for their business and the invite to the event. jdf

09/23/2008 - Jason XXXXXX called with an RFP for 1,000+ lineal feet for the proposed Lake County Campus project in Libertyville. This is good news because they have the master planning contract for that site and we should be in line to get the buildings when they go. I reminded Jason of our XXXXX office in Lake County. jdf

09/19/2008 - Bryan XXXX called with an RFP for geo on a project in Schaumburg. Since MDB already is working on the same one for other consultants he will handle this one as well. jdf
May 26 '11 #1
1 1760
Dormilich
8,658 Expert Mod 8TB
if there is no return inside the paragraphs, you can explode() the string on that (after removing all content up to the dashes).
May 27 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Nazgul | last post by:
Hi! I want to implement a small tool in Python for distributing "patches" and I need Your advice. This application should be able to package all files chosen by a user into a self-extracting.exe...
2
by: Avi | last post by:
hi, Can anyone tell me what the problem is and how to solve it The following piece of code resides on an asp page on the server and is used to download files from the server to the machine...
0
by: k_nil | last post by:
I have a link on my web page for a self extracting executable file placed on the server. When the link is clicked, 1) i could see dialog box with open or save options 2) when open clicked, self...
1
by: Adam Faulkner via DotNetMonster.com | last post by:
I had a problem before extracting pages from an existing word document and then inserting the content into a new word document. The following code below works with Microsoft Word 2000 Function...
1
by: Jean-François Michaud | last post by:
Hello people, I was wondering how it I could implement keep with next logic on lines of text contained within a paragraph. I need to have at least 10 lines of text within a paragraph to be...
14
by: Adnan Siddiqi | last post by:
Hi Suppose I have following URLs comming from an HTML document <a href="http://mydomain1.com">Domain1</a> <a...
2
by: bjm | last post by:
I created a self extracting zip file with about 9000 files in it. I extracted it manually from the command line without a problem. However, when I tried to do the same extraction at the same...
6
by: Werner | last post by:
Hi, I try to read (and extract) some "self extracting" zipefiles on a Windows system. The standard module zipefile seems not to be able to handle this. False Is there a wrapper or has...
3
by: gentsquash | last post by:
I'm trying to display a paragraph that has a centered phrase, such as this one, in the middle of the paragraph. An example is the section "End of semester project" on my course-page ...
6
by: Haines Brown | last post by:
I'm trying to resolve a contradictory situation in which I have rows going down a page, and each consists of two elements: to the left is a thumbnail image that is a hot link; to its right is a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.