preg_replace

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

    preg_replace

    Hi!

    When replacing with preg_replace e. g.:

    $Month_Strings = array('/Jan/','/Feb/','/Mar/','/Apr/','/May/','/Jun/',
    '/Jul/','/Aug/','/Sep/','/Oct/','/Nov/','/Dec/');
    $Month_Numbers = array('1','2',' 3','4','5','6',
    '7','8','9','10 ','11','12');

    $month_number = preg_replace($M onth_Strings, $Month_Numbers, $month, 1);


    How can I get an error message if nothing was replaced?

    Bye,
    Thomas
  • Justin Koivisto

    #2
    Re: preg_replace

    Thomas Schandl wrote:
    [color=blue]
    > Hi!
    >
    > When replacing with preg_replace e. g.:
    >
    > $Month_Strings = array('/Jan/','/Feb/','/Mar/','/Apr/','/May/','/Jun/',
    > '/Jul/','/Aug/','/Sep/','/Oct/','/Nov/','/Dec/');
    > $Month_Numbers = array('1','2',' 3','4','5','6',
    > '7','8','9','10 ','11','12');
    >
    > $month_number = preg_replace($M onth_Strings, $Month_Numbers, $month, 1);
    >
    >
    > How can I get an error message if nothing was replaced?
    >
    > Bye,
    > Thomas[/color]

    Take a look into the preg_replace_ca llback function... of possibly use
    preg_match_all first.

    --
    Justin Koivisto - justin@koivi.co m

    Comment

    • steve

      #3
      Re: preg_replace

      "Thomas Schandl" wrote:[color=blue]
      > Hi!
      >
      > When replacing with preg_replace e. g.:
      >
      > $Month_Strings =
      > array('/Jan/','/Feb/','/Mar/','/Apr/','/May/','/Jun/',
      >
      > '/Jul/','/Aug/','/Sep/','/Oct/','/Nov/','/Dec/');
      > $Month_Numbers = array('1','2',' 3','4','5','6',
      > '7','8','9','10 ','11','12');
      >
      > $month_number = preg_replace($M onth_Strings, $Month_Numbers,
      > $month, 1);
      >
      >
      > How can I get an error message if nothing was replaced?
      >
      > Bye,
      > Thomas[/color]

      do a strlen on the result, and if less than 3 chars, it is an error
      (caution: NOT a general solution, but works in your case).

      --
      Posted using the http://www.dbforumz.com interface, at author's request
      Articles individually checked for conformance to usenet standards
      Topic URL: http://www.dbforumz.com/PHP-preg_rep...ict208838.html
      Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=714343

      Comment

      Working...