Friday, May 9, 2008

Make Money?

I have been browsing DigitalPoint Forums these days. Many people are making money with their websites or blogs. So I'm considering whether I can make some money with this blog.

I've been using Google Adsense, but the effect is not good. Last year I started Adsense but now my account has only $2.16. What a pity! Of course that blog is written in Chinese. Most people think that English content may bring better ads. Last year I planned to write English but I'm afraid my English level. Now I know, no matter how much I will earn, I will be successful, because I can improve my language level and share my experience all over the world.

I registered LinkWorth for my Chinese blog last day. LinkWorth is similar to Text Link Ads and it supports paid reviews and text link ads, etc. Besides, LinkWorth is more appropriate for small blogs. If your site's traffic is small, you should try LinkWorth probably. But I regret that there are few Chinese ads. It doesn't matter, I think. By the way, LinkWorth provides a tool which can evaluate your site's value. I tried it for my Chinese blog. Surprisingly, it told me a link ads on my homepage values $50 - $60. I don't know how it works. Maybe it's just a joke?

PS: If you want to try LinkWorth, please use this link to register and enter 12368 in referral id. So when you earn $100 I will get $50. Thank you.

Wednesday, May 7, 2008

The Difference Between mysql_fetch_array() And mysql_fetch_assoc()

Getting data from MySQL with PHP is very convenient. But I found most of PHP beginners don't know the difference between two MySQL functions: mysql_fetch_array() and mysql_fetch_assoc(). If you don't understand the two functions, you always come up against such problem: why can't I see the result from MySQL?

Suppose we have a database called 'test' and it has a table called 'members' which stores some members' information. The goal is to fetch all the members' information. Consider such code below:

$conn=mysql_connect('localhost','root','');
$mysql_select_db('test');
$rs=mysql_query('SELECT * FROM members');


Then $rs is an array that stores all personal information. You can use mysql_fetch_array() or mysql_fetch_assoc() to fetch each row by calling the function repeatedly. Consider:

while ($row=mysql_fetch_array($rs,MYSQL_NUM)){
// ...
}

Here $row is a normal array (integer-indexed array). You cannot get data with $row['name'], $row['birthday'], etc. You must use integer as the index, e.g. $row[0], $row[1]... How to get an associative array? You need to set the second parameter of mysql_fetch_array(). MYSQL_ASSOC tells mysql_fetch_array() to return an associative array. See below:

while ($row=mysql_fetch_array($rs,MYSQL_ASSOC)){
// ... here you can use $row['name'], $row['birthday']...
}


mysql_fetch_array($rs,MYSQL_BOTH) equals to mysql_fetch_array($rs). There's no need to use MYSQL_BOTH, so we often omit it.

So you can use two methods to fetch data by specifying the second parameter to MYSQL_BOTH or omitting the second parameter. Then both of the styles, $row[0] and $row['name'], are available.

But where's mysql_fetch_assoc()? It seems not useful. Right. mysql_fetch_assoc($rs) is equivalent to mysql_fetch_array($rs,MYSQL_ASSOC). Obviously, when you need to an associated array (string-indexed array) only, mysql_fetch_assoc() is more convenient. By the way, mysql_fetch_assoc doesn't have the second parameter. It can only return associative array so it needs less memory space to store the result array.

Sunday, May 4, 2008

I Feel Afraid

When you are using Internet to send information, do you think that your information can be viewed on the Internet? Well, it is technically feasible. For example, if you want to send a mail, after you press "send" button, the mail will be sent to an SMTP server, then it will be transferred among several servers. Don't forget that your mail is usually plain text. Everyone can understand your mail if he can access to the mail server where your mail is located.

I feel afraid...

Maybe the best way is that everyone has a pair of RSA password keys. One for yourself (private key) and the other for public (public key). The passwords is two very large number. For example, if you have two numbers m and n, where m is your private key and n is your public key. Before you send a mail, you can use m to encrypt your message. When the recipient received the mail, he can use n to decrypt the message. Remember, n is your public key so your friend can get it, but you must protect your private key. If your friend wants to send mail to you, he need to use your public key, n, to encrypt the message. Then after you recieved the cryptographic message, you need to use your private key, m, to decrypt the message.

Wrote lots of things regarding RSA encryption algorithm. I think it's safety enough for business. But what if your friends who know your public key betray you, e.g. tell your public key to other suspicious people, then he can decrypt your message? I don't know how to avoid it.

There are some tools which support RSA, such as GnuPG (opensource software), PGP Desktop (commercial software).

Friday, May 2, 2008

Running PHP In The Console

When you test a small PHP script, you need run a web server, such as Apache, then open a browser to see the result. How dirty the work is! The simple method to run a PHP file is to call PHP interpretor in the console.

For Unix/Linux, the only thing you need to do is enter such line in the console:

php -f your_php_file


For Windows, the best way to run a PHP script is to call PHP interpretor from a text editor or IDE. I like SciTE, a powerful text editor for programming. Open html.properties from options menu, then add these lines in the bottom:

PHP_Bin=D:\xampplite\php
command.go.$(file.patterns.php)=$(PHP_Bin)\php.exe -f "$(FileNameExt)"
command.compile.$(file.patterns.php)=$(PHP_Bin)\php.exe -l "$(FileNameExt)"


"PHP_Bin" specifies where the PHP interpretor is. After doing that, when you open a PHP file next time, you can run it in SciTE just select "Tools" -> "Go" or press F5. If you select "Tools" -> "Compile" or press Ctrl+F7, PHP interpretor doesn't run the script but check syntax instead.

Thursday, May 1, 2008

What's BBCode?

BBCode is short for "Bulletin Board Code". It is a markup language which is similar to HTML and it is widely used on forums. So it is also called "forums code". Many forums don't accpte HTML code so you can't use HTML to format your text. Most of forums support BBCode. For example, if you want to use bold text, just type "It is [b]bold text[/b]." then the program of the forum changes it into HTML code "It is <b>bold text</b>.".

Below are most useful BBCode markups:
  • [b]bolded text[/b]: bolded text
  • [i]italicized text[/i]: italicized text
  • [u]underlined text[/u]: underlined text
  • [url]http://deepbluespaces.blogspot.com/[/url]: http://deepbluespaces.blogspot.com/
  • [url=http://deepbluespaces.blogspot.com/]Deepblue Spaces[/url]: Deepblue Spaces
The normal method to parse BBCode is "Regular Expression" which is widely used to handle string problem. I plan to write something about regular expression in a few days.