Help with Php and Regex

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

    Help with Php and Regex

    I'm just wondering what the best way is to extract and display a
    number from a html file.

    I tried the following piece of code, however it does not work.

    ereg('\d\.\d', $content, $reg);
    echo $reg[0];

  • Mattia Gentilini

    #2
    Re: Help with Php and Regex

    The.Relinator@g mail.com ha scritto:
    I'm just wondering what the best way is to extract and display a
    number from a html file.
    >
    I tried the following piece of code, however it does not work.
    >
    ereg('\d\.\d', $content, $reg);
    echo $reg[0];
    ereg() is a test function, it checks if a regexp matches a given string
    and returns a boolean.
    You probably need ereg_replace($r egexp, $substitute, $input); see the
    doc for details.

    --
    |\/|55: Mattia Gentilini e 55 cappuccini per svegliarsi (by Sigfrido)
    |/_| ETICS project at CNAF, INFN, Bologna, Italy
    |\/| www.getfirefox.com www.getthunderbird.com
    * Using Mac OS X 10.4.9 powered by Cerebros (Core 2 Duo) *

    Comment

    • gosha bine

      #3
      Re: Help with Php and Regex

      On 31.05.2007 14:10 The.Relinator@g mail.com wrote:
      I'm just wondering what the best way is to extract and display a
      number from a html file.
      >
      I tried the following piece of code, however it does not work.
      >
      ereg('\d\.\d', $content, $reg);
      echo $reg[0];
      >
      Don't use ereg, it's deprecated.

      preg_match_all( '/-? ( \d+\.?\d* | \.\d+) /x', $html, $matches);

      finds numbers like "12", "-123.456" and ".789" and places them in array
      $matches.



      --
      gosha bine

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

      Comment

      Working...