Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Advanced Regex Help needed
    primarykey
    data
    text
    <p>So I have many large text paragraphs to parse. The end goal is to separate the paragraphs into smaller postings, so I can insert them into mysql.</p> <p>Here's a very short example of one of the paragraphs in a string:</p> <pre><code>&lt;?php $longstring = ' (&lt;b&gt;John Smith&lt;/b&gt;) at &lt;b class="datetimeGMT"&gt;2011-01-10 22:13:01 GMT&lt;/b&gt;&lt;hr&gt; Lots of text entered here under the first line.&lt;br&gt;And most of it is html, since it is for displaying in a web browser.&lt;br&gt;&lt;/br&gt;&lt;/br&gt; (&lt;b&gt;Alan Slappy&lt;/b&gt;) at &lt;b class="datetimeGMT"&gt;2011-01-11 13:12:00 GMT&lt;/b&gt;&lt;hr&gt; Forgot to put one more thing in the notes.........&lt;br&gt;blah blah blah (&lt;b&gt;Joe Mama&lt;/b&gt;) at &lt;b class="datetimeGMT"&gt;2011-01-13 10:15:00 GMT&lt;/b&gt;&lt;hr&gt; Groceries list:&lt;br&gt;Watermelons&lt;br&gt;Floss&lt;br&gt;&lt;br&gt;email doctor '; ?&gt; </code></pre> <p>Yep, I have a freaky project of parsing these strings for each entry. Yes, I agree with anyone that this is not a cool task. the original developer allowed for appending text to the original text. Not a bad idea for some occasions, but for me it is.</p> <p>I do need help with how to RegEx this beast and place it into a foreach loop so I can start cleaning it up.</p> <p>Here's how far I got:</p> <pre><code>&lt;?php if(preg_match_all('/\(&lt;b&gt;.*?&lt;hr&gt;/', $longstring, $matches)){ print_r($matches); } /* output: Array ( [0] =&gt; Array ( [0] =&gt; (&lt;b&gt;John Smith&lt;/b&gt;) at &lt;b class="datetimeGMT"&gt;2011-01-10 22:13:01 GMT&lt;/b&gt;&lt;hr&gt; [1] =&gt; (&lt;b&gt;Alan Slappy&lt;/b&gt;) at &lt;b class="datetimeGMT"&gt;2011-01-11 13:12:00 GMT&lt;/b&gt;&lt;hr&gt; [2] =&gt; (&lt;b&gt;Joe Mama&lt;/b&gt;) at &lt;b class="datetimeGMT"&gt;2011-01-13 10:15:00 GMT&lt;/b&gt;&lt;hr&gt; ) ) */ ?&gt; </code></pre> <p>So, I'm actually doing pretty good with looping through the tops of each entry. I'm kinda proud I figured that out. (regex is my nemesis)</p> <p>So now I'm stuck figuring out how to include the actual text below each iteration.</p> <p>Anyone have an idea on how I can adjust the <code>preg_match_all</code> to account for the text below each "header"?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload