Hey Justin. Sorry for the late reply -- got totally wrapped up in utilizing that highly useful bit of reg exp code.
Thanks for the heads up; it certainly solved the problem. Unfortunately, or fortunately, new problems have arisen -- time to dive into learning some reg exp syntax........ Thanks again, --Noah "Justin French" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > on 28/05/03 2:56 PM, CF High ([EMAIL PROTECTED]) wrote: > > > > I've got a chunk of HTML text I'd like to format for insertion into our > > mySql db. > > > > Let's say $html_string equals the following: > > > > <tr> > > <td>1</td> > > <td>Bardo, Jesse</td> > > <td>S</td> > > <td>A</td> > > <td>Andover, MA</td> > > </tr> > > > > To setup this chunk of text for insertion I first use > > strip_tags($html_string); that results in: > > > > 1 > > Bardo, Jesse > > S > > A > > Andover, MA > > > > I then use str_replace(",","",$html_string) to create a space delimited > > string. > > exactly... for starters, there might be tabs (\t), newlines (\n, \r, \n\r), > plus multiple spaces (" "). > > this is DEFINITELY a quick hack, adapted from code on > au.php.net/preg-replace... someone with more regular expression knowledge > can probably get this down to 1 or 2 lines, with a perfomance gain as well > :) > > <? > > $html = "<tr> > <td>1</td> > <td>Bardo, Jesse</td> > <td>S</td> > <td>A</td> > <td>Andover, MA</td> > </tr>"; > > $html = preg_replace ("'<[\/\!]*?[^<>]*?>'si", ' ', $html); > $html = preg_replace ("'([\r\n])[\s]+'", ' ', $html); > $html = preg_replace ("([\s]+)", ' ', $html); > $html = trim($html); > > echo "<pre>"; print_r($html); echo "</pre>"; > > ?> > > You'll need to test it thoroughly, and make sure it's ok on larger blocks of > text, like whatever your target source is, to make sure it doesn't bog > anything down. > > > > Justin > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php