Removing HTML tags using mysql

Try this (ported from a T-SQL func by Robert Davis):


SET GLOBAL log_bin_trust_function_creators=1;
DROP FUNCTION IF EXISTS fnStripTags;
DELIMITER |
CREATE FUNCTION fnStripTags( Dirty varchar(4000) )
RETURNS varchar(4000)
DETERMINISTIC
BEGIN
  DECLARE iStart, iEnd, iLength int;
    WHILE Locate( ‘<‘, Dirty ) > 0 And Locate( ‘>’, Dirty, Locate( ‘<‘, Dirty )) > 0 DO
      BEGIN
        SET iStart = Locate( ‘<‘, Dirty ), iEnd = Locate( ‘>’, Dirty, Locate(‘<‘, Dirty ));
        SET iLength = ( iEnd – iStart) + 1;
        IF iLength > 0 THEN
          BEGIN
            SET Dirty = Insert( Dirty, iStart, iLength, ”);
          END;
        END IF;
      END;
    END WHILE;
    RETURN Dirty;
END;
|
DELIMITER ;
SELECT fnStripTags(‘this <html>is <b>a test</b>, nothing more</html>’);


Exploring Mysql CURDATE and NOW. The same but different.


Sometimes I see people attempting to use VARCHARS or CHARS to store dates in their MySQL database application. This is really fighting against MySQL, which has a variety of interchangeable date types. Internally MySQL is storing dates as numbers, which allows it to do all sorts of nice arithmetic and comparisons with very little effort on your part. For example, when you use a mysql DATE column to store a date, you don’t have to worry about sortation, or comparing that date to another DATE, because MySQL already understands how to do those things internally. A lot of people also don’t realize that they can output a DATE column in just about any way they choose using the DATE_FORMAT function. This causes people to shy away from using DATE, DATETIME, TIME, or TIMESTAMP columns, when they really should.


We can break down mysql DATE columns into 3 categories:

DATE: Has no Time component.

DATETIME and TIMESTAMP: Has both Date and Time component.

TIME: Has only Time component.


I tend to use DATETIME most often, and occassionally will use TIMESTAMP. I’ll talk about TIMESTAMP another day, and explain the pros and cons of using it.

In this entry I’m going to concentrate on two very important MySQL date functions: CURDATE() and NOW(). Take a look at these examples, and keep in mind that the semicolons are added to terminate the SQL statements as you would have to if you were using the mysql client application. If you’re using phpMyAdmin you don’t need the semicolons.


SELECT CURDATE();



CODE:

+————+
| CURDATE()  |
+————+
| 2004-11-30 |
+————+
1 row in set (0.00 sec)


CURDATE() returns you the date part of the mysql server’s datetime. The server gets this from the operating system, so basically it’s whatever the Date/Time is on the machine that is running your mysql server.

Notice that CURDATE() as its name implies has no TIME component. Let’s assume that what your application needs to do is find out what date it was “yesterday”. If Time really isn’t important, then CURDATE is the way to go, as it’s not concerned with TIME.

Although it’s not that intuitive, the way to get “YESTERDAY” is to use the DATE_ADD() function. The INTERVAL component allows us to Add a -1 DAY


SELECT DATE_ADD(CURDATE(), INTERVAL1 DAY);



CODE:

+————————————–+
| DATE_ADD(CURDATE(), INTERVAL -1 DAY) |
+————————————–+
| 2004-11-29                           |
+————————————–+
1 row in set (0.00 sec)


This is not to say that you can’t then use the DATE to compare against a DATETIME. You can! What happens is that mysql assumes for comparison purposes that your DATE is the equivalent to the “first second of that day” or that day at 12:00 am.

This little experiment illustrates the idea.


CODE:

mysql> create table onedate (onedate DATETIME);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into onedate VALUES(NOW());
Query OK, 1 row affected (0.00 sec)

mysql> select * from onedate where onedate >= CURDATE();
+———————+
| onedate             |
+———————+
| 2004-11-30 17:52:01 |
+———————+
1 row in set (0.00 sec)


Notice that a row was returned, because CURDATE() will always be less than or equal to NOW().

Compare CURDATE() with NOW(). Like CURDATE(), NOW() returns you the system DATE but also includes the time component. If you need TIME in your application, tracking logins, or the date and time a message was entered by a user, then you need a mysql DATETIME rather than a MYSQL date, or you will not be able to capture the important time component.


SELECT * FROM onedate WHERE onedate >= CURDATE();



CODE:

+———————+
| NOW()               |
+———————+
| 2004-11-30 18:00:34 |
+———————+
1 row in set (0.00 sec)


Notice the 24 Hour time component.

Putting a nail in the issue, here’s the same DATE_ADD function called against NOW().


SELECT NOW(), DATE_ADD(NOW(), INTERVAL1 DAY);



CODE:

+———————+———————————-+
| NOW()               | DATE_ADD(NOW(), INTERVAL -1 DAY) |
+———————+———————————-+
| 2004-11-30 18:07:17 | 2004-11-29 18:07:17              |
+———————+———————————-+
1 row in set (0.00 sec)


What we get is exactly the same time, yesterday.

The intrinsic DATE types in a relational database are always the way to go when you need to handle date and time in your application. Let the database do the heavy lifting, and you will make your application faster, more reliable and easier to maintain in the long run.

Illuminati Pinball 彈珠台遊戲

Illuminati Pinball 彈珠台遊戲

軟體:Illuminati Pinball(版本:N/A)
類別:動作遊戲
性質:Freeware()

【編輯/宗文】

這是一款彈珠台遊戲,玩家的目標是追求高分。要達到此目標,必須利用畫面下方的兩個檔板來彈射彈珠,當彈珠撞擊台面上的各種不同物品時便能獲得分數。為了持續得分,玩家必須要提防彈珠落入畫面正下方的洞口。

遊戲中擊中物品所得分數都不同,像是撞擊底色為藍色的骷髏頭可得5分,而如為黃底的骷髏頭則能獲得10分,如能打入畫面上方紅色區域的兩個洞口可獲得 100分。另外難度較高,而可得較高分數的是左右兩側的軌道,玩家如能順利打上,則左側軌道可獲得300分,右側軌道可以獲得400分的高分。要取得高分就要利用檔板,等待球落下的角度,並且抓準時機,如此才有較多機會打入可得高分區域。

遊戲操控方面,利用方向鍵中的下鍵將球從出口處彈出,利用左右兩鍵來控制檔板。


下載:http://www.qplaygames.com/playgame.htm?gid=9

Breakit 3 打磚塊遊戲

Breakit 3 打磚塊遊戲

軟體:Breakit 3(版本:N/A)
類別:動作遊戲
性質:Freeware()

【編輯/宗文】

這是一款打磚塊遊戲,玩家必須將關卡中的磚塊全部破壞才能順利過關。遊戲中要避免的就是不要讓鋼球掉落,否則會扣一生命值。打磚塊遊戲要打的好,除了能不讓鋼球掉落外,角度的拿捏也是一大重點,另外玩家如能將鋼球打入一堆磚塊的上方,讓它在磚塊上自由移動,這是非常有效率的銷毀磚塊的方式。



遊戲中提供了多種寶物,例如使鋼球變成破壞力極大的火球的寶物,或一次增加多顆球的寶物,又或者在檔板下方行成一保護網的寶物等等,這些寶物讓遊戲更加豐富,另外玩家如能善於利用,這些寶物也將是幫助玩家過關的利器。遊戲中玩家擊毀一些磚塊時,會掉落分數的圖示,玩家如能用檔板來接住,如此可以獲得額外的分數。



遊戲操控方面,利用滑鼠移動來控制檔板。


下載:http://www.terrypaton.com/game.php?game=breakit3

Derby JDBC Connection

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.Properties;

public class MainClass {
   public static void main(String[] args)
   {
      try {
         String driver = “org.apache.derby.jdbc.EmbeddedDriver”;

         Class.forName(driver).newInstance();
         Connection conn = null;
         conn = DriverManager.getConnection(“jdbc:derby:DerbyTestDB”);
         Statement s = conn.createStatement();
         ResultSet rs = s.executeQuery(“SELECT city, state, zipcode FROM zipcodes”);

         while(rs.next()) {
            System.out.println(“City   : “+ rs.getString(1));
            System.out.println(“State  : “+ rs.getString(2));
            System.out.println(“Zipcode: “+ rs.getString(3));
            System.out.println();
         }

         rs.close();
         s.close();
         conn.close();
      catch(Exception e) {
         System.out.println(“Exception: “+ e);
         e.printStackTrace();
      }
   }
}


Connect to Java DB (Derby) with org.apache.derby.jdbc.EmbeddedDriver

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class JavaDBDemo {
  static Connection conn;

  public static void main(String[] args) {
    String driver = “org.apache.derby.jdbc.EmbeddedDriver”;
    String connectionURL = “jdbc:derby:myDatabase;create=true”;
    String createString = “CREATE TABLE Employee (NAME VARCHAR(32) NOT NULL, ADDRESS VARCHAR(50) NOT NULL)”;
    try {
      Class.forName(driver);
    catch (java.lang.ClassNotFoundException e) {
      e.printStackTrace();
    }
    try {
      conn = DriverManager.getConnection(connectionURL);
      Statement stmt = conn.createStatement();
      stmt.executeUpdate(createString);

      PreparedStatement psInsert = conn.prepareStatement(“insert into Employee values (?,?)”);

      psInsert.setString(1, args[0]);
      psInsert.setString(2, args[1]);

      psInsert.executeUpdate();

      Statement stmt2 = conn.createStatement();
      ResultSet rs = stmt2.executeQuery(“select * from Employee”);
      int num = 0;
      while (rs.next()) {
        System.out.println(++num + “: Name: ” + rs.getString(1“\n Address” + rs.getString(2));
      }
      rs.close();
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}


BEGIN and END Statements

mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION myProc (cost DECIMAL(10,2))
    -> RETURNS DECIMAL(10,2)
    ->
    -> SQL SECURITY DEFINER
    ->
    -> tax: BEGIN
    ->     DECLARE order_tax DECIMAL(10,2);
    ->     SET order_tax = cost * .05;
    ->     RETURN order_tax;
    -> END
    -> //
Query OK, rows affected (0.00 sec)

mysql> DELIMITER&nbsp$$
mysql>
mysql> select myProc(123.45);
+—————-+
| myProc(123.45|
+—————-+
|           6.17 |
+—————-+
row in set, warning (0.00 sec)

mysql>
mysql> drop function myProc;
Query OK, rows affected (0.00 sec)

mysql>


Heatsoft Clone Cleaner Lite 清除電腦中無用的檔案複本

Heatsoft Clone Cleaner Lite 清除電腦中無用的檔案複本

軟體:Heatsoft Clone Cleaner Lite(版本:1.05)
類別:檔案工具
性質:Freeware(1.4 M)

【編輯/何詩琦】

在網路族和上班族時常使用電腦來瀏覽網頁、文書處理時,自然而然經常產生內容類似或檔名類似的無用檔案複本,其中很可能是大量文件在經常複製修改而產生,也可能是網路下載的結果,想要一口氣把她們做個整理嗎?Heatsoft Clone Cleaner Lite 是個不錯的選擇。

第一次執行 Heatsoft Clone Cleaner Lite 的時候它會自動搜尋整個磁碟中的所有文件,不但是由檔名去判斷複本文件,它還會逐字比對內容,即使檔名差異很大但是事實上是差不多的文件也能被挑出來喔!然後的步驟就是讓使用者自己抉擇要刪除還是做整理、合併、複製、移動等動作。

但若是誤刪了重要系統檔或軟體必備元件怎麼辦?Heatsoft Clone Cleaner Lite 主視窗 Option 下 General 分頁中記得不要解除 Protect Windows folder 和 Protect idden folders 就不會刪到重要系統檔了。

下載:http://www.clonecleaner.com/HCCLITEheat.zip

Windows Live Writer 強大的 MSN Live 離線編寫工具

Windows Live Writer 強大的 MSN Live 離線編寫工具

軟體:Windows Live Writer(版本:N/A)
類別:網頁編輯
性質:Freeware(1.7 M)

【編輯/何詩琦】

在越來越多人使用 Microsoft Live Space 之後,微軟又提出了部落格最佳編寫工具 ─ Windows Live Writer,它是主要用於 Live Space 或國外英文主流網站的部落格離線編輯軟體,不但功能強大而且操作簡單,對於 Blog 一族來說可是一大福音!

Windows Live Writer 當然也具備所見即所得的編輯介面,可以用拖拉方式直接新增本機的圖片、加入超連結、放置網路地圖、加入視訊影片,各樣功能應有盡有,而且重要的是,這些動作都能離線的狀態下完成,然後一口氣上傳,再也不需要心情記事寫到一半還等慢慢等待圖片上傳了。

在文字和圖像編輯的功能大致如同好用的網頁編輯工具,對於圖片大小、特效、文字內容效果等都可以做細部的編修,唯一比較稍嫌不足的是無法在 Windows Live Writer 編輯時直接點選加入 MSN 特有的可愛表情符號。

下載:http://g.live.com/1rebeta/zh-tw/WLInstaller.exe