Re: strip_tags() Quandry....
| From: | CF High | Date: | Thu, 29 May 2003 16:33:19 +0000 |
| Subject: | Re: strip_tags() Quandry.... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-149393@lists.php.net to get a copy of this message | ||
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" <justin@indent.com.au> wrote in message
news:BAFA6BAC.2804D%justin@indent.com.au...
> on 28/05/03 2:56 PM, CF High (noah@newminddesign.com) 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
>