Archive

Archive for the ‘Chỉ dẫn lập trình’ Category

Zend_Gdata_App_HttpException: Unable to Connect to ssl://www.google.com:443

March 10th, 2010 admin No comments

Windows OS:
Config php.ini (php-cli.ini)
;extension=php_openssl.dll
remove ; (comment char)
extension=php_openssl.dll

Linux OS:
If the php had not compile with the option –with-openssl, then add the option and recomplie it.

Categories: Chỉ dẫn lập trình Tags: ,

file_get_contents with context

March 6th, 2010 admin No comments

$context = stream_context_create(array(
‘http’ => array(
‘method’ => ‘POST’,
‘header’ => //sprintf(”Authorization: Basic %s\r\n”, base64_encode($username.’:’.$password)).
“Content-type: application/x-www-form-urlencoded; ; charset=UTF-8\r\n” .
“User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6″
,
‘content’ => http_build_query(array(’q’ => ‘đan ‘)),
‘timeout’ => 5,
),
));
$ret = file_get_contents(’http://phungvanhuy.net/application/index/search’, false, $context);

Categories: Chỉ dẫn lập trình Tags: ,

Nếu chỉ là script

March 6th, 2010 admin No comments

Build mấy cái đơn giản thì chả cần framework mà làm gì, cứ require với include mà giã! Nhớ lại ngày trước toàn include “openDB.php”, include “closeDB.php” ^^ thấy hay phết. Hôm nay thay đổi tí cho nó có không khí (cái gì mãi cũng nhàm :p), tạo hứng thú với cốt đinh

File: connect_db.php
$conn = mysql_connect('pvh', 'huypv', 'oHr61th3') or die("Connect failed to MySQL Server");
mysql_select_db('xxx', $conn) or die("Select db failed");

register_shutdown_function('closeDBConnection');
function closeDBConnection() {
global $conn;
if ($conn) mysql_close($conn);
}

File: index.php
require_once "connect_db.php";
function execSQL() {
global $conn;
//...
}
// execSQL();
# Không phải lo đóng connection

Categories: Chỉ dẫn lập trình Tags:

Tiếng Việt khi xài ajax với jQuery

March 5th, 2010 admin No comments

$.ajax({
url: “/xxx/search.php”,
type: “POST”,
contentType: “application/x-www-form-urlencoded; charset=UTF-8″,
data: “term=chống phá cách mạng, tuyên truyền phản động, xuyên tạc chủ nghĩa Mác – như thế là sai&_r=25251325″,
success: function(data) {
//console.log(data);
alert(data);
}
});

VBA function MoneyFromNote

February 10th, 2010 admin No comments

Function MoneyFromNote(ByVal note As String)
    
    Dim RE As RegExp, REMatches As MatchCollection, REMatch As Match
    Set RE = CreateObject("vbscript.regexp")
    With RE
        .MultiLine = False
        .Global = True
        .IgnoreCase = True
        .Pattern = "([\+0-9\.,]+)([MK])"
    End With
    
    Set REMatches = RE.Execute(note)
    r = 0
    For i = 0 To REMatches.Count – 1
        Set REMatch = REMatches.Item(i)
        unit = REMatch.SubMatches(1)
        num = REMatch.SubMatches(0)
        
        num = Replace(num, ",", ".")
        If unit = "M" Then
            va = num * 1000000
        ElseIf unit = "K" Then
            va = num * 1000
        End If
        If Mid(num, 1, 1) = "+" Then va = 0 – va
        'MsgBox num & " " & unit & " = " & va
        r = r – va
    Next
    'MsgBox r
    MoneyFromNote = Int(r)
End Function

‘Usage example
‘=MoneyFromNote(”Quần đùi: 30K; Áo ba lỗ: 25K; Thịt ba chỉ: 15K”)
‘Sẽ thu được: -70000

Minh họa hàm MoneyFromNote trong Excel

Categories: Chỉ dẫn lập trình Tags: ,