caine Posted October 30, 2006 Share Posted October 30, 2006 I had few problems with my code. The problems are: (i) unable to store data into mysql database table including current date publications(ii) having problem programming the refreshing url part for data updating I would like to gain assistance with these. Can anybody help with these? I'm working on extracting news/bulletin from the $URL and store into database "bulletin" with table name "bul_data". The html source file can be found from the $URL. <?php $URL="http://bulletin.mmu.edu.my/v3/view/bytodaytitle.mmu"; $f = fopen($URL, "r"); if($f) while($pre = fread($f, 1000)) $source = $source.$pre; else { echo 'Unable to open '.$URL.'.'; die; } include 'connect.php'; //extract the date into database //$date_string= substr_count($source, "<td width=\"100%\" colspan=\"4\">"); //$date1 = strpos($source, "<td width=\"100%\" colspan=\"4\"><font face=\"Verdana, Arial\" size=\"1\" // color=\"#000066\">List of Today's Bulletin : <b>", 0); //$date_end1 = strpos($source, "</b></font></td>", $date1); //$date1 = $date1 + strlen($date1); //$date = substr($source, $date1, $date_end1- $date1;); //$date = check($date); //@mysql_query("INSERT INTO `bul_data` VALUES ('$date')", $db); $total= substr_count($source, "<td width=\"20%\" >");//extract necessary information into database $pos=0;for($counter=0;$counter<$total;$counter++){ $line1 = strpos($source, "<td width=\"20%\" ><font face=\"Verdana, Arial\" size=\"1\">", $pos); $end1 = strpos($source, "</a></td></font>", $begin1); $line1 = $line1 + strlen($line1); $end1 = $end1 - $line1; $department = substr($source, $line1, $end1); $department = check($department); $line2 = $line1 + $end1 + 1; $line2 = strpos($source, "<a href=\"", $line2); $end2 = strpos($source , "\" target=\"main\"" , $line2); $line2 = $line2 + strlen($line2); $end2 = $end2 - $line2; $link = substr($source , $line2, $end2); $link = check($link); $line3 = $line2 + $end2 + 1; $line3 = strpos($source , "onMouseOut=\"b()\">" , $begin3); $end3 = strpos($source , "</font></a></td>" , $begin3); $line3 = $line3 + strlen($line3); $ended = $end3 - $line3; $title = substr($source , $line3 , $ended); $title = check($title); $line4 = $line3 + $ended + 1; $line4 = strpos($source , "<td width=\"17%\" align=\"center\"><font face=\"Verdana, Arial\" size=\"1\">" , $begin4); $end4 = strpos($source , "</td></font>" , $begin4); $line4 = $line4 + strlen($line4); $end4 = $end4 - $line4; $campus = substr($source , $begin4 ,$line4); $campus = check($campus); $pos = $line4 + $end4 + 1; @mysql_query("INSERT INTO `bul_data` VALUES ('$title', '$department', '$campus', '$link')", $db); }function check($string){ $string = htmlspecialchars($string, ENT_QUOTES); //$string = str_replace("&", "&", $string); //$string = str_replace("<", "<", $string); //$string = str_replace(">", ">", $string); //$string = str_replace("'", "'", $string); //$string = str_replace("\"", """, $string); return $string;}***********//problem with this refreshing part for information update*****************//function ripnew($URL){ $newURL="http://bulletin.mmu.edu.my/v3/view/$URL"; $f = fopen($newURL, "r"); if($f) while($pre = fread($f, 1000)) $source = $source.$pre; else { echo 'Unable to open '.$URL.'.'; return false; } $begin = strpos ($source,"</table>", 0); $begin = $begin + 8; $end = strpos($source,"</body>",$begin); $end = $end - $begin; $detail = substr($source, $begin, $end); return $detail;}?>This is the connect.php file:<html><head><title></title></head><body><?php$host="localhost";$username="root"; //unknown$password=""; //unknown$dbname="bulletin"; $db = mysql_connect("$host", "$username", "$password") or die("Unable to connect"); mysql_select_db("$dbname") or die(mysql_error());?></body><html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.