Hiển thị danh ngôn ngẫu nhiên bằng PHP trên blogspot

Người đăng: ngaybennhau on Thứ Năm, 3 tháng 11, 2011

Cũng như ngôn ngữ Javascript, mình đến với PHP chỉ bằng con đường tự mày mò nghiên cứu trong những thời gian rảnh rỗi và chưa từng trải nghiệm qua bất kỳ khóa học nào. Quả thật, PHP không dễ cảm thụ, nhưng mình nghĩ các bạn có thể học được nếu có lòng kiên trì và đam mê. Hy vọng qua những ví dụ từ dễ đến khó được ứng dụng trên nền tảng Blogspot, các bạn sẽ từng bước hiểu được tường tận về ngôn ngữ PHP.

Qua bài này, mình sẽ giúp bạn hiển thị những câu danh ngôn một cách ngẫu nhiên theo như DEMO bên dưới (nhấn F5 để thấy tác dụng).



Điều trước tiên là bạn cần có một hosting (có thể dùng free hosting như byethost.com để thử nghiệm). Mở công cụ Notepad trên máy tính của bạn rồi dán vào đó bằng đoạn code bên dưới rồi lưu file với tên là randomquotes.php.

  1. <?
  2. //////////////////////////////////////////////////////
  3. // PHP Random Quote Script for Blogspot applied by www.thuthuatblogger.info
  4. // Many thanks to http://davidmarotz.com/ for its original PHP code
  5. //////////////////////////////////////////////////////
  6. Header("content-type: application/x-javascript");
  7. $bgcolor = '#FFFFCC';
  8. $textcolor = 'black';
  9. $textcolor2 = 'brown';
  10. $textsize = '4';
  11. $textsize2 = '3';
  12. // Array Structure:  "Quote","Author"
  13. $allqts = array
  14.     ("The Black Knight Always Triumphs!",
  15.         "Monty Python",
  16.     "I swear by my life and love of it that I will never live for the sake of<br>another man, nor ask another man to live for mine" ,
  17.         "Atlas Shrugged",
  18.     "It is clear that the individual who persecutes a man, his brother,<br> because he is not of the same opinion, is a monster",
  19.         "Voltaire",
  20.     "I agree that there is a natural aristocracy among men<br>The grounds of this are virtue and talents.",
  21.         "Thomas Jefferson",
  22.     "Liberty, when it begins to take root, is a plant of rapid growth.",
  23.         "George Washington",
  24.     "Never argue with an idiot. <br>They drag you down to their level <br>then beat you with experience",
  25.         "Dilbert",
  26.     "The Answer is 42. What is the question?",
  27.         "Hitchikers Guide to the Galaxy",
  28.     "Anyone who has never made a mistake has never tried anything new",
  29.         "Albert Einstein",
  30.     "Progress doesn't come from early risers, progress is made<br>by lazy men looking for easier ways to do things.",
  31.         "Lazarus Long <font size=-2>(Time Enough for Love by Robert A. Heinlein)</font>",
  32.     "Throughout history, poverty is the normal condition of man. <br>Advances which permit this norm to be exceeded - here and there, now and then - <br>are the work of an extremely small minority, frequently despised,<br> often condemned, and almost always opposed by all right-thinking people. <br>Whenever this tiny minority is kept from creating, or (as sometimes happens)<br> is driven out of a society, the people then slip back into abject poverty.<br><br>This is known as 'bad luck.'",
  33.         "Robert Heinlein",
  34.     "A little learning is a dangerous thing; Drink deep, or taste not the<br>Pierian spring.  There shallow draughts intoxicate the brain, <br>and drinking largely sobers us again",
  35.         "Alexander Pope",
  36.     "The early bird gets the worm, but the second mouse gets the cheese",
  37.         "Anonymous",
  38.     "Subjugating the enemy's army without fighting is the true pinnacle of excellence",
  39.         "Sun-tzu, The Art of War",
  40.     "Work as though you were to live 100 years; pray as if you were to die tomorrow",
  41.         "Benjamin Franklin",
  42.     "The world is a stage, but the play is badly cast",
  43.         "Oscar Wilde",
  44.     "Truth is generally the best vindication against slander.",
  45.         "Abraham Lincoln",
  46.     "...mercy to the guilty is cruelty to the innocent...",
  47.         "Adam Smith",
  48.     "...I wish that I may never think the smiles of the great and powerful<br> a sufficient inducement to turn aside from the straight path<br> of honesty and the convictions of my own mind",
  49.         "David Ricardo",
  50.     "Democracy is the worst form of government except for all the others",
  51.         "Winston Churchill",
  52.     "You can only know the highest peaks if you have experianced the lowest valley's",
  53.             "Richard Nixon",
  54.     "They dress the wound of my people as though it were not serious. <br>'Peace, peace,' they say, when there is no peace.",
  55.         "Jeremiah 6:14",
  56.     "It is better to remain silent and be thought a fool<br> than to open your mouth and remove all doubt.",
  57.         "Jonathan Swift",
  58.     "The market system delivers the goods people want,<br>but those who make it work cannot readily explain why it is so.<br>The socialst or communist system does not deliver the goods, <br>but those who operate it can readily explain away its failure.",
  59.         "F.A. Hayek, Law, Legislation and Liberty, Vol. II",
  60.     "Never Stop Exploring<sup>tm</sup>",
  61.         "The North Face"
  62.         );
  63. // Gets the Total number of Items in the array
  64. //  Divides by 2 because there is a Quote followed by an Author
  65. $totalqts = (count($allqts)/2);
  66. // Subtracted 1 from the total because '0' is not accounted for otherwise
  67. $nmbr = (rand(0,($totalqts-1)));
  68. $nmbr = $nmbr*2;
  69. //$nmbr = 18;
  70. $quote = $allqts[$nmbr];
  71.          $nmbr = $nmbr+1;
  72. $author = $allqts[$nmbr];
  73. $space = "<font color=$bgcolor>.....................................</font>";
  74. echo "document.write(\"<center><font color=$textcolor size='$textsize'><i>$quote</i></font><br>$space<font color=$textcolor2 size='$textsize2'>$author</font></center>\")";
  75. ?>

Trong đoạn code trên, bạn có thể thay thế những câu danh ngôn tiếng Anh bằng những câu danh ngôn tiếng Việt tương ứng, thêm hoặc bớt tùy ý theo đúng định dạng. Chú ý dùng <br> để xuống dòng cho câu văn.

Upload file randomquotes.php lên hosting của bạn để sử dụng.

Để hiển thị danh ngôn thì bạn đặt trong bài viết Blogspot hoặc tiện ích HTML/Javascript bằng dòng code như sau:

  1. <script type="text/javascript" src="http://www.tenmienhostingcuaban.com/randomquotes.php"></script>
Chạy PHP bằng Javascript ngoại
Danh ngôn ngẫu nhiên bằng Javascript
More about →

Cuộc thi dự đoán thứ hạng đội tuyển U23 Việt Nam tại SEA Games 26

Người đăng: ngaybennhau

Đội tuyển bóng đá U23 Việt Nam sẽ có trận cầu đầu tiên quan trọng chiều nay với đội U23 Philippines. Với lòng nhiệt thành của một fan hâm mộ thật sự đối với bóng đá Việt Nam, thay mặt Ban Quản trị Thủ thuật Blogger, xin chúc các chàng trai trẻ của đội tuyển U23 Việt Nam sẽ có một trận đấu cống hiến, chiến thắng chính mình và chiến thắng đối thủ, để lại nhiều cảm xúc sâu sắc cho khán giả và người xem truyền hình. Xin chúc đội tuyển U23 Việt Nam sẽ thi đấu ấn tượng suốt đại hội thể thao SEA Games 26, vượt qua mọi đối thủ để đi đến trận đấu cuối cùng và đứng trên bục vinh quang cao nhất để thỏa lòng người hâm mộ Việt Nam.


Đồng hành cùng đội tuyển bóng đá U23 Việt Nam tham dự SEA Game 26, Thủ thuật Blogger tổ chức cuộc thi dự đoán thứ hạng của đội tuyển U23 Việt Nam tại giải đấu này.

* Thể lệ cuộc thi như sau:

1. Chủ đề: Dự đoán thứ hạng của đội tuyển bóng đá nam U23 Việt Nam tại SEA Games 26. Các thứ hạng gồm: vô địch, á quân, hạng ba, hạng tư, không có thứ hạng.

2. Thời gian tham gia dự đoán: 04/11 – 15/11/2011.

3. Giải thưởng:

- 1 giải nhất: Một Blogger Template trị giá 10 USD;

- 1 giải nhì: 01 suất tùy biến Template theo yêu cầu trị giá 5 USD.

Người trúng giải nhất là người dự đoán đúng thứ hạng của đội tuyển và dự đoán gần đúng nhất về số người có cùng câu trả lời. Nếu kết thúc chương trình, có từ 2 bạn đọc trở lên cùng dự đoán đúng thì Ban Tổ chức sẽ trao giải cho bạn đọc có thời gian dự đoán đúng sớm nhất. Người trúng giải nhì là người dự đoán đúng thứ hạng của đổi tuyển và dự đoán gần đúng nhất về số người có cùng câu trả lời sau người trúng giải nhất.

Để tham gia cuộc thi, bạn đọc soạn tin nhắn theo cú pháp:

U23VN [Thứ hạng] [Số người cùng dự đoán như bạn] gửi 0909841270

Chúc các bạn may mắn!

* Kết quả dự đoán công bố ngày 22/11/2011:

Có 3 người dự đoán như sau:
- Số điện thoại 01278882345 dự đoán U23 Việt Nam vô địch, số người cùng dự đoán là 500
- Số điện thoại 0972990892 dự đoán U23 Việt Nam xếp hạng 3, số người cùng dự đoán là 92
- Số điện thoại 0977504688 dự đoán U23 Việt Nam xếp hạng 3, số người cùng dự đoán là 2.

Rất tiếc không có bạn nào trúng giải. Chân thành cảm ơn các bạn. Hẹn các bạn ở lần sau.
More about →

TeraCopy Pro v2.22

Người đăng: ngaybennhau on Thứ Tư, 2 tháng 11, 2011

TeraCopy Pro v2.22 Final

Copy files faster. TeraCopy uses dynamically adjusted buffers to reduce seek times. Asynchronous copy speeds up file transfer between two physical hard drives. Pause and resume file transfers. Pause copy process at any time to free up system resources and continue with a single click.








More about →

HIỂN THỊ BÀI VIẾT TRONG CÙNG MỘT NHÃN (KIỂU 2)

Người đăng: ngaybennhau on Thứ Ba, 1 tháng 11, 2011

Với thủ thuật này, các bài viết trong cùng một nhãn sẽ hiển thị một hình ảnh đại diện phía trên, dưới hình ảnh là tiêu đề bài đăng. Và được trình diễn chạy tự động từ phải qua trái hay ngược lại.
Bạn bấm vào thẻ XEM THỬ để trải nghiệm trước.



Đầu tiên, bạn đăng nhập vào Blog > chọn Thiết kế > Chỉnh sửa HTML, bấm cặp phím Ctrl+F để mở hộp tìm kiếm và gõ vào đó dòng lệnh ]]></b:skin> và dán trước dòng lệnh đó đoạn code phía dưới

.bgcontent{background:#efefef; /*màu nền của tiện ích*/
height:140px; /*chiều cao của tiện ích*/
width:500px; /*độ rộng của tiện ích*/
}
#rc-content {
padding:4px;
width:500px; /*độ rộng của tiện ích*/
}
#rc-main {
width:110px;
background:#fff url(https://lh5.googleusercontent.com/_9-sNIAfGhKg/TXXfgP5zNLI/AAAAAAAAAGU/Dh1jYQZoSgM/main-bg.png) repeat-y;
}
#rc-top {
background:#fff url(https://lh3.googleusercontent.com/_9-sNIAfGhKg/TXXff4uaqaI/AAAAAAAAAGQ/cj2q0Y_nb-A/top-bg.png) no-repeat top;
height:3px;
}
#rc-bottom {
background:#fff url(https://lh5.googleusercontent.com/_9-sNIAfGhKg/TXXffoEZMJI/AAAAAAAAAGM/JJSC-pSoUTk/bottom-bg.png) no-repeat bottom;
height:3px;
}
.rc-thumbs {
padding:2px 5px 5px 5px;
height:70px;
}
.rc-thumbs IMG {
width:100px; /*độ rộng của ảnh thumbnail*/
height:70px; /*chiều cao của ảnh thumbnail*/
}
.rc-title {
height:48px;
padding:0px 3px 2px 3px;
line-height:1.3em;
font-size:11px;
font-weight:bold;
}
.rc-title a {color:#0000ff;}
.rc-title a:hover {color:#ff0033;}

Bạn bấm Lưu lại và trở lại Thiết kế > Thêm tiện ích HTML/Javacript rồi tiếp tục dán đoạn code phía dưới vào

<div style="font-weight:bold; border: 2px #30a1db solid; padding:5px; text-align:center; background:#FFF380;">Thủ thuật Win 7</div>
<div class="bgcontent">
<script language="JavaScript">
imgr = new Array();
imgr[0] = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfo9sYuhQyJhEoLwz17UsZU1WwayQS-iHkGpeOIvTESJKGOj2cfUMCLiHttGmKXwOzUMSR0WJ0XpJYJvSpeFYRrbKjgm9bSGFWiswMlV6Fp7tx5UNvryUHMGUDgEdvdvUTGNGEJZ1yu4zt/";
showRandomImg = true;
zaBold = false;
numposts = 20; //số bài trình diễn trong tiện ích
label = "WIN 7"; //thay thành tên nhãn của blog bạn
summaryTitle = 40; //số ký tự của tiêu đề bài viết
home_page = "http://www.dungheineken.blogspot.com/"; //thay thành địa chỉ blog bạn
</script>

<marquee align="center" direction="left" height="150" onmouseout="this.start()" onmouseover="this.stop()" scrollamount="5" width="500">
<script src="http://dl.dropbox.com/u/66348944/rc_label.js" type="text/javascript">
</script>
</marquee></div>

<p style="float:right;margin:0;padding:3px">Xem tất cả<a href="http://dungheineken.blogspot.com/search/label/WIN%207"> Thủ thuật Win 7 &#187;</a></p>

Bây giờ bạn dựa theo các phần ghi chú trong code (màu đỏ) để chỉnh sửa lại cho phù hợp với ý thích của mình và Bấm lưu lại.
Nếu không muốn tiện ích này hiển thị các bài viết trong nhãn mà hiển thị hết cho các bài ở Blog thì bạn thay chữ label (màu vàng) thành chữ allpost là xong


Lưu ý: Bạn phải điền chính xác tên nhãn, địa chỉ Blog của mình và quan trọng nhất là số bài trình diễn trong tiện ích phải bằng hoặc ít hơn số bài trong cùng một nhãn, nếu số bài trình diễn trong tiện ích nhiều hơn số bài hiện có trong nhãn thì hình ảnh sẽ không được hiển thị...
More about →

Driver Reviver v3.1.648.11122

Người đăng: ngaybennhau

Driver Reviver v3.1.648.11122

Driver Reviver is an industry leading PC Driver Update utility that will help you update your computer drivers in just a few clicks. Driver Reviver uses one of the largest and most comprehensive Driver libraries available, ensuring that it will always find the most recent drivers for you device or hardware. Try Driver Reviver TODAY and find out how many of your drivers are out of date.










More about →

Hide IP Easy v5.1.2.6

Người đăng: ngaybennhau

Hide IP Easy v5.1.2.6

Hide IP Easy – Protect Your Privacy Easily on the Internet. Browsing on the Internet is becoming more and more dangerous in today’s world. Hackers and identity thieves are trying to use IP address to get any information out of you: home address, credit card information, social security information, your bank accounts and other personal information.









More about →

Super Hide IP v3.1.5.2

Người đăng: ngaybennhau

Super Hide IP v3.1.5.2


Surf anonymously, change your IP address, protect your personal information against hackers and provide full encryption of your online activity, all with the click of a button. Protect your privacy on the Internet. Use Super Hide IP to surf anonymously, prevent hackers from monitoring your online activities or identity thieves from stealing your identity and other personal information, send anonymous email, and un-ban yourself from forums or restricted websites. With Super Hide IP, you are able to be assigned one of our fake IP addresses which can be from different countries such as United States, United Kingdom, France, etc. Super Hide IP works with Internet Explorer, Firefox, Opera, Maxthon, MyIE and is compatible with all types of routers, firewalls, home networks, wireless networks and any other kind of Internet.











More about →