|
Posted by Rik Wasmus on 10/29/07 21:31
On Mon, 29 Oct 2007 21:42:22 +0100, joanna <me@barrelofcrafts.com> wrote:
> Hi, I'm using preg_replace to strip out a bunch of unwanted stuff from
> the database. However the results seem to bunch up. Here's what I'm
> doing
>
> $old = htmlspecialchars($row['name']);
>
> $new = preg_replace("/[^a-zA-Zs]/", "", $old);
>
> the results of this are
>
> TomSmith
>
> instead of
>
> Tom Smith
>
> What do I need to add to the expression to get the desired space
> between words?
$new = preg_replace("/[^\w\s]/", "", $old);
Then again, why do a htmlspecialchars() if you're going to maim them
anyway? There's '&',';',0-9, etc... 'André Tös' might object to being
called 'Andreacute Toumls'. Also, try to store information as it is in a
database, not the presentation. While it might seem a good idea to use
htmlspecialchars() once here, it will be a pain when you're going to
search the database, or output data in other formats like a downloadable
report (pdf, txt, whatever).
What is it exactly that you don't want there, and why?
--
Rik Wasmus
Navigation:
[Reply to this message]
|