preg_grep question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • paladin.rithe@gmail.com

    preg_grep question

    This is probably simple, but I want to pull out data (not count) from
    a string, and the preg_grep looked like the best option. I'm pulling
    an entry out of the database (which is a text field), a sample being:
    Note #13 for Task #23 added to the system. I want to pull the 13, and
    the 23 out. (probably need 2 different calls, but that's ok).
    The problem that I'm having though is this: Warning: preg_grep()
    expects parameter 2 to be array, string given in table.php on line 18

    Here is the code for that line: $note = preg_grep("/^Note #([0-9]+)/",
    $text);
    $text is the value of $row['text'] (tried $row['text'] first, but had
    the same thing).

    Now, I thought that something of type text would be a string/array, so
    why doesn't it like it? I'm running PHP 5.2.1 right now, if that
    helps any.

  • gosha bine

    #2
    Re: preg_grep question

    On 05.06.2007 22:38 paladin.rithe@g mail.com wrote:
    This is probably simple, but I want to pull out data (not count) from
    a string, and the preg_grep looked like the best option. I'm pulling
    an entry out of the database (which is a text field), a sample being:
    Note #13 for Task #23 added to the system. I want to pull the 13, and
    the 23 out. (probably need 2 different calls, but that's ok).
    The problem that I'm having though is this: Warning: preg_grep()
    expects parameter 2 to be array, string given in table.php on line 18
    >
    Here is the code for that line: $note = preg_grep("/^Note #([0-9]+)/",
    $text);
    $text is the value of $row['text'] (tried $row['text'] first, but had
    the same thing).
    >
    Now, I thought that something of type text would be a string/array, so
    why doesn't it like it? I'm running PHP 5.2.1 right now, if that
    helps any.
    >
    You want preg_match or preg_match_all, not preg_grep.

    --
    gosha bine

    extended php parser ~ http://code.google.com/p/pihipi
    blok ~ http://www.tagarga.com/blok

    Comment

    • paladin.rithe@gmail.com

      #3
      Re: preg_grep question

      On Jun 5, 4:58 pm, gosha bine <stereof...@gma il.comwrote:
      On 05.06.2007 22:38 paladin.ri...@g mail.com wrote:
      >
      >
      >
      This is probably simple, but I want to pull out data (not count) from
      a string, and the preg_grep looked like the best option. I'm pulling
      an entry out of the database (which is a text field), a sample being:
      Note #13 for Task #23 added to the system. I want to pull the 13, and
      the 23 out. (probably need 2 different calls, but that's ok).
      The problem that I'm having though is this: Warning: preg_grep()
      expects parameter 2 to be array, string given in table.php on line 18
      >
      Here is the code for that line: $note = preg_grep("/^Note #([0-9]+)/",
      $text);
      $text is the value of $row['text'] (tried $row['text'] first, but had
      the same thing).
      >
      Now, I thought that something of type text would be a string/array, so
      why doesn't it like it? I'm running PHP 5.2.1 right now, if that
      helps any.
      >
      You want preg_match or preg_match_all, not preg_grep.
      >
      --
      gosha bine
      >
      extended php parser ~http://code.google.com/p/pihipi
      blok ~http://www.tagarga.com/blok
      But I want to pull the data out. I know it's already there.
      preg_match just tells me how many matches there are (in this case, 1)

      Comment

      • gosha bine

        #4
        Re: preg_grep question

        paladin.rithe@g mail.com wrote:
        On Jun 5, 4:58 pm, gosha bine <stereof...@gma il.comwrote:
        >On 05.06.2007 22:38 paladin.ri...@g mail.com wrote:
        >>
        >>
        >>
        >>This is probably simple, but I want to pull out data (not count) from
        >>a string, and the preg_grep looked like the best option. I'm pulling
        >>an entry out of the database (which is a text field), a sample being:
        >>Note #13 for Task #23 added to the system. I want to pull the 13, and
        >>the 23 out. (probably need 2 different calls, but that's ok).
        >>The problem that I'm having though is this: Warning: preg_grep()
        >>expects parameter 2 to be array, string given in table.php on line 18
        >>Here is the code for that line: $note = preg_grep("/^Note #([0-9]+)/",
        >>$text);
        >>$text is the value of $row['text'] (tried $row['text'] first, but had
        >>the same thing).
        >>Now, I thought that something of type text would be a string/array, so
        >>why doesn't it like it? I'm running PHP 5.2.1 right now, if that
        >>helps any.
        >You want preg_match or preg_match_all, not preg_grep.
        >>
        >--
        >gosha bine
        >>
        >extended php parser ~http://code.google.com/p/pihipi
        >blok ~http://www.tagarga.com/blok
        >
        But I want to pull the data out. I know it's already there.
        preg_match just tells me how many matches there are (in this case, 1)
        >
        I'd suggest you just read documentation



        Return array entries that match the pattern


        --
        gosha bine

        extended php parser ~ http://code.google.com/p/pihipi
        blok ~ http://www.tagarga.com/blok

        Comment

        • paladin.rithe@gmail.com

          #5
          Re: preg_grep question

          On Jun 5, 5:46 pm, gosha bine <stereof...@gma il.comwrote:
          paladin.ri...@g mail.com wrote:
          On Jun 5, 4:58 pm, gosha bine <stereof...@gma il.comwrote:
          On 05.06.2007 22:38 paladin.ri...@g mail.com wrote:
          >
          >This is probably simple, but I want to pull out data (not count) from
          >a string, and the preg_grep looked like the best option. I'm pulling
          >an entry out of the database (which is a text field), a sample being:
          >Note #13 for Task #23 added to the system. I want to pull the 13, and
          >the 23 out. (probably need 2 different calls, but that's ok).
          >The problem that I'm having though is this: Warning: preg_grep()
          >expects parameter 2 to be array, string given in table.php on line 18
          >Here is the code for that line: $note = preg_grep("/^Note #([0-9]+)/",
          >$text);
          >$text is the value of $row['text'] (tried $row['text'] first, but had
          >the same thing).
          >Now, I thought that something of type text would be a string/array, so
          >why doesn't it like it? I'm running PHP 5.2.1 right now, if that
          >helps any.
          You want preg_match or preg_match_all, not preg_grep.
          >
          --
          gosha bine
          >>
          But I want to pull the data out. I know it's already there.
          preg_match just tells me how many matches there are (in this case, 1)
          >
          I'd suggest you just read documentation
          >
          PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

          >
          --
          gosha bine
          >
          extended php parser ~http://code.google.com/p/pihipi
          blok ~http://www.tagarga.com/blok
          Ahhh... I missed the extra parameters for preg_match.... I was
          looking at what was returned. Silly me. Thanks.

          Comment

          Working...