Re: Help with Php and Regex



On 31.05.2007 14:10 The.Relinator@xxxxxxxxx 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
.



Relevant Pages

  • Re: help with eval usage
    ... I'm trying to get it to echo 2 ... extended php parser ~ http://code.google.com/p/pihipi ... blok ~ http://www.tagarga.com/blok ...
    (comp.lang.php)
  • Re: Script Need to check disk space on remote servers
    ... Is it possible to get SQL Server database and log information (like ... echo Checking drives on Server %%S... ... REM this part of the script generates an HTML file with all the ... REM and then launches it using the default browser. ...
    (microsoft.public.windows.server.scripting)
  • Re: Error checking on SaveAs
    ... Echo ... > I am working on an add-in that looks at an HTML file and pulls text from a ... > I have no illusions that this will get all possible illegal characters. ...
    (microsoft.public.word.vba.userforms)
  • Re: Help with Php and Regex
    ... The.Relinator@xxxxxxxxx ha scritto: ... number from a html file. ... echo $reg; ... ereg() is a test function, it checks if a regexp matches a given string and returns a boolean. ...
    (comp.lang.php)
  • Re: $_POST array returns no data
    ... the array returns 0 no matter what I send ... is in the same folder as the .html file. ... As for trying just "echo ...
    (comp.lang.php)