2 files here (kind of long, if you can find a better way of doing it just let me know b/c I'm REALLY new at this)...
This program basically takes a stock page from Yahoo and strips it down to ONLY the date I need and the stockwatch.php program strips it down farther and adds a '/' in between the diff. sets of data.
What do I do to get each set of data between the '/' to go into a string of my choice...
i.e. There are 8 sets of data that are divided by a '/' sign and I must seperate them out into their own strings with a string name of my choice for each set (i.e. sybmol, name, market_cap, etc). How would I do so? I tried the explode command but couldn't figure it out right...
BTW, http://www.printmergers.com/sw/ has the files that this script produces if you want to view how this is being outputted...
lib.php:
<?php
function roughdraft($symbol)
{
$filename = "http://finance.yahoo.com/q?s=\$symbol\&d=v4";
$start = "More Info";
$stop = "Chart";
$cache = "cache.html";
$h_page = "header.html";
$f_page = "footer.html";
$roughd = "roughdraft.html";
// Get contents of the specified URL and writes it into a string
$fd = fopen( $filename, "r" );
$contents = fread( $fd, 20000 );
fclose( $fd );
// Isolates desired section.
if(eregi("$start(.*)$stop", $contents, $printing)) {
$substring=$printing[1];
while(eregi("(.*)$stop", $substring, $printing)) {
$substring=$printing[1];
};
} else {
echo "Error, please check your source code.";
}
// Replaces specific HTML tags and text
$printing[1] = eregi_replace( "<font[^>]*>", "", $printing[1] );
$printing[1] = eregi_replace( "</font>", "", $printing[1] );
$printing[1] = eregi_replace( "</th>", "", $printing[1] );
$printing[1] = eregi_replace( "<small>", "", $printing[1] );
$printing[1] = eregi_replace( "</small>", "", $printing[1] );
$printing[1] = eregi_replace( "<b>", "", $printing[1] );
$printing[1] = eregi_replace( "</b>", "", $printing[1] );
$printing[1] = eregi_replace( "<table[^>]*>", "", $printing[1] );
$printing[1] = eregi_replace( "</table>", "", $printing[1] );
$printing[1] = eregi_replace( "<tr[^>]*>", "<tr>", $printing[1] );
$printing[1] = eregi_replace( "<td[^>]*>", "</td>", $printing[1] );
$printing[1] = eregi_replace( "</tr>", "</tr>", $printing[1] );
$printing[1] = eregi_replace( "</td>", "</td><td>", $printing[1] );
$printing[1] = eregi_replace( "Chart", "", $printing[1] );
$printing[1] = eregi_replace( ",", "", $printing[1] );
$printing[1] = eregi_replace( "<a href=[^>]*>", "", $printing[1] );
$printing[1] = eregi_replace( "</a>", "", $printing[1] );
// Saves the header file to cache
$cartFile = fopen("$cache","w");
fwrite($cartFile,$printing);
fclose($cartFile);
// What appears on the head of the HTML file
$header = "startcleanup";
// Saves the header file to cache
$cartFile = fopen("$h_page","w");
fwrite($cartFile,$header);
fclose($cartFile);
// What appears on the footer of the HTML file
$footer = "endcleanup";
// Saves the header file to cache
$cartFile = fopen("$f_page","w");
fwrite($cartFile,$footer);
fclose($cartFile);
// Puts both cache files into one string
$final = $header . $printing[1]. $footer;
// Writes above variable into HTML file
$cartFile = fopen("$roughd","w");
fwrite($cartFile,$final);
fclose($cartFile);
return 0;
}
function finaldraft($symbol)
{
$filename = "http://www.printmergers.com/sw/roughdraft.html";
$start = "startcleanup";
$stop = "endcleanup";
$h_page = "header.html";
$f_page = "footer.html";
$finald = "news.html";
// Get contents of the specified URL and writes it into a string
$fd = fopen( $filename, "r" );
$contents = fread( $fd, 20000 );
fclose( $fd );
// Isolates desired section.
if(eregi("$start(.*)$stop", $contents, $finalize)) {
$substring=$finalize[1];
while(eregi("(.*)$stop", $substring, $finalize)) {
$substring=$finalize[1];
};
} else {
echo "Error, please check your source code.";
}
$finalize[1] = eregi_replace( "</tr><tr></td><td>", "<tr><td>", $finalize[1] );
$finalize[1] = eregi_replace( "</td><td></td><td>", "</td><td>", $finalize[1] );
// What appears on the head of the HTML file
$header = "<table width=75% border=1>";
// Saves the header file to cache
$cartFile = fopen("$h_page","w");
fwrite($cartFile,$header);
fclose($cartFile);
// What appears on the footer of the HTML file
$footer = "</table>";
// Saves the header file to cache
$cartFile = fopen("$f_page","w");
fwrite($cartFile,$footer);
fclose($cartFile);
// Puts both cache files into one string
$final = $header . $finalize[1]. $footer;
// Writes above variable into HTML file
$cartFile = fopen("$finald","w");
fwrite($cartFile,$final);
fclose($cartFile);
return 0;
}
?>
stockwatch.php:
<?php
include ('lib.php');
roughdraft();
finaldraft();
$url = 'http://www.printmergers.com/sw/news.html';
$lines_array = file($url);
$lines_string = implode('', $lines_array);
eregi("<table[>]>(.)</table>", $lines_string, $printing);
// Strip HTML tags
$printing[0] = eregi_replace( "<table[>]*>", "", $printing[0] );
$printing[0] = eregi_replace( "</table>", "", $printing[0] );
$printing[0] = eregi_replace( "</tr><tr>", "", $printing[0] );
$printing[0] = eregi_replace( "</td><td>", "/", $printing[0] );
$slash = explode("\/\", $printing);
$temp = ereg_replace("\/\","",$slash[$i]);
$html = explode("/", $temp);
echo $html;
?>