Code: Select all
P/E</td><td class="cl1">6.20Code: Select all
\d+\.\d*Code: Select all
$result = curl_exec($ch);
curl_close($ch);
$pattern='#\w\W\w\W+\w+\W+\w+\s\w+\W+\w+\W+(\d+\W\d*)#i';
preg_match($pattern,$result,$match);
print_r($match);Moderator: General Moderators
Code: Select all
P/E</td><td class="cl1">6.20Code: Select all
\d+\.\d*Code: Select all
$result = curl_exec($ch);
curl_close($ch);
$pattern='#\w\W\w\W+\w+\W+\w+\s\w+\W+\w+\W+(\d+\W\d*)#i';
preg_match($pattern,$result,$match);
print_r($match);Code: Select all
Array ( [0] => 0 s 0 v 0 l 0) [1] => 0) )Code: Select all
$subject = 'P/E</td><td class="cl1">6.20';
$pattern = '/<td class="cl1">([\d+.]+)/';
preg_match($pattern, $subject, $matches);
echo $matches[1];Code: Select all
preg_match("/>(\d+(\.\d+)?)/i",$str,$matches);
echo $matches[1];Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
here is my code now:Code: Select all
$result = curl_exec($ch);
curl_close($ch);
$pattern='#[P\E]</td><td class="cl1">([\d+.]+|\w+)#';
preg_match($pattern,$result,$match);
print_r($match);Code: Select all
Array ( [0] => ENA [1] => NA )Code: Select all
Array ( [0] => E28.60 [1] => 28.60 )Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]Then give us more data. I don't know "MSN money pages", do they have e.g. an url? Something to test on?afbase wrote:the "P/E" is a critical identifier not so much the "<td class='c11'>", If i try either code, it will just return incorrect data. Instead of posting the P/E ratio, it returns the previous day's close.
Code: Select all
$url = "http://moneycentral.msn.com/detail/stock_quote?ipage=qd&Symbol=US%3A".$_GET['ticker'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$result = curl_exec($ch);
curl_close($ch);
$pattern='#[P\][E]</td><td class="cl1">([\d+.]+|\w+)#i';
preg_match($pattern,$result,$match);
print_r($match);Code: Select all
$testdata = array(
'http://moneycentral.msn.com/detail/stock_quote?Symbol=wgo',
'http://moneycentral.msn.com/detail/stock_quote?Symbol=zoom'
);
$pattern = '!<tr><td>P/E</td><td class="cl1">([^<]*)</td></tr>!';
foreach($testdata as $url) {
$subject = file_get_contents($url);
preg_match($pattern, $subject, $matches);
$pe = $matches[1];
echo $url, ' -> ', $pe, "<br />\n";
}Code: Select all
<?php
$url = "http://moneycentral.msn.com/detail/stock_quote?ipage=qd&Symbol=US%3A".$_GET['ticker'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$result = curl_exec($ch);
curl_close($ch);
$pattern='!P/E</td><td class="cl1">([^<]*)</td></tr>!';
preg_match($pattern,$result,$match);
print_r($match);
?>