adding space between words preg_replace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joanna

    #1

    adding space between words preg_replace

    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 = htmlspecialchar s($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?

  • Jerry Stuckle

    #2
    Re: adding space between words preg_replace

    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 = htmlspecialchar s($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@attgl obal.net
    =============== ===

    Comment

    • Rik Wasmus

      #3
      Re: adding space between words preg_replace

      On Mon, 29 Oct 2007 21:42:22 +0100, joanna <me@barrelofcra fts.comwrote:
      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 = htmlspecialchar s($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 htmlspecialchar s() 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
      htmlspecialchar s() 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

      Comment

      • joanna

        #4
        Re: adding space between words preg_replace

        On Oct 29, 5:31 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
        On Mon, 29 Oct 2007 21:42:22 +0100, joanna <m...@barrelofc rafts.comwrote:
        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 = htmlspecialchar s($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 htmlspecialchar s() 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
        htmlspecialchar s() 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 htmlspecialchar s as it is in fact
        redundant.

        Thank You

        Comment

        • joanna

          #5
          Re: adding space between words preg_replace

          On Oct 29, 5:31 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
          On Mon, 29 Oct 2007 21:42:22 +0100, joanna <m...@barrelofc rafts.comwrote:
          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 = htmlspecialchar s($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 htmlspecialchar s() 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
          htmlspecialchar s() 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 htmlspecialchar s as it is in fact
          redundant.

          Thank You

          Comment

          Working...