adding space between words preg_replace
adding space between words preg_replace
am 29.10.2007 21:42:22 von Joanna
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?
Re: adding space between words preg_replace
am 29.10.2007 22:29:56 von Jerry Stuckle
joanna 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?
>
>
Untried, but maybe something like:
$new = preg_replace("/[^a-zA-Z\s]/", "", $old);
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: adding space between words preg_replace
am 29.10.2007 22:31:23 von luiheidsgoeroe
On Mon, 29 Oct 2007 21:42:22 +0100, joanna 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
Re: adding space between words preg_replace
am 30.10.2007 00:23:44 von Joanna
On Oct 29, 5:31 pm, "Rik Wasmus" wrote:
> On Mon, 29 Oct 2007 21:42:22 +0100, joanna wrot=
e:
> > 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 =3D htmlspecialchars($row['name']);
>
> > $new =3D 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 =3D 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=E9 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
That worked and yes I removed the htmlspecialchars as it is in fact
redundant.
Thank You
Re: adding space between words preg_replace
am 30.10.2007 01:41:53 von Joanna
On Oct 29, 5:31 pm, "Rik Wasmus" wrote:
> On Mon, 29 Oct 2007 21:42:22 +0100, joanna wrot=
e:
> > 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 =3D htmlspecialchars($row['name']);
>
> > $new =3D 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 =3D 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=E9 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
That worked and yes I removed the htmlspecialchars as it is in fact
redundant.
Thank You