By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Help with Php and Regex

P: n/a
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];

May 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Th***********@gmail.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($regexp, $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) *
May 31 '07 #2

P: n/a
On 31.05.2007 14:10 Th***********@gmail.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
May 31 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.