Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[PHP] ´Ó json_encode µ½ ajax_encode

PHP 5.2 ¼°ÒÔÉÏ°æ±¾ÌṩÁË json_encode ºÍ json_decode º¯Êý£¬Ï൱ºÃÓá£
¶ø֮ǰµÄ°æ±¾ÔòÐèÒªÏÂÔØÍøÓÑÃÇ×ÔÐпª·¢µÄ¿â£¨ÓÐÐËȤµÄ¿ÉÒÔ¿´Ï http://code.itlearner.com/php/JSON-class.html £©
¿ÉÒԲο¼ÈçÏÂÕâ¸ö·½·¨À´ÔڵͰ汾ÉÏÀ©³äÕâÁ½¸öº¯Êý£º
if (!function_exists('json_encode') && !function_exists('json_decode')) {
require_once ROOT . 'include/json.class.php';
$g_service_json = new Services_JSON;
function json_encode($arr) {
global $g_service_json;
return $g_service_json->encode($arr);
}
function json_decode($arr) {
global $g_service_json;
return $g_service_json->decode($arr);
}
}
 
Èç´ËÒ»À´£¬ÄãÒ²¿ÉÒÔÔڵͰ汾µÄ PHP ÉÏʹÓà json_encode ºÍ json_decode º¯ÊýÁË¡£
¶ø¶ÔÓÚ xml µÄÊä³ö£¬µ±È»¿ÉÒÔʹÓà xml µÄ¿â£¬È»¶øÈÕ³£¿ª·¢ÖУ¬ÇáÁ¿¼¶µÄʹÓà xml Êä³öÆäʵ²¢²»ÐèҪ̫¹ý¸´ÔӵŦÄÜ¡£
Òò´ËÎÒдÁËÒ»¸ö¸ü¼òµ¥µÄ ajax_encode º¯Êý£¬ÓÐÐËȤµÄÐֵܿÉÒԲο¼Ï£º
/**
* Description:
* A simple function for outputing XML
* History:
* Created by Moky @ 2009-11-26
*/
/**
Usage:
$xml = '<?xml version="1.0" encoding="utf-8" ?>' . "\r\n";
$xml .= ajax_encode($data, 'data');
*/
function ajax_encode($var, $name = 'data') {
if (!$var && !is_numeric($var) && is_bool($var)) return "<$name/>\r\n";
$xml = '';
if (is_array($var)) {
foreach ($var as $k => $v) {
if (is_numeric($k)) $k = 'item';
$xml .= self::ajax_encode($v, $k);
}
} else if (is_string($var)) {
$xml .= "<!--[CDATA[$var]]-->";
} else {
$xml .= $var;
}
return "<$name>$xml</$name>\r\n";
}
 


Ïà¹ØÎĵµ£º

¼ÌÐøÕª³­£º½ÌÄãÓÃPHPдMySQLÊý¾Ý¿âµÄÓû§ÈÏ֤ϵͳ

Óû§ÈÏÖ¤µÄÔ­ÀíºÜ¼òµ¥£ºÊ×ÏÈÐèÒªÓû§ÔÚÒ³ÃæÉÏÌîÈëÓû§ÃûºÍÃÜÂ룬µ±È»Ã»×¢²áµÄÓû§ÐèÒªÏÈ×¢²á¡£È»ºóµ÷ÓÃÊý¾Ý¿âËÑË÷ÊÇ·ñÓÐÏàÓ¦µÄÓû§¡£Èç¹ûÓоÍÈ·ÈÏ£¬Ã»ÓÐÔòÌáÐÑÓû§ÏÈ×¢²á¡£Ê¹ÓÃPHPÀ´Íê³ÉÕâÒ»Çкܼòµ¥£¬µ«ÐèҪעÒâµÄÊÇÈç¹ûÏëÔÚÒÔºóµÄÒ³ÃæÖж¼ÄÜÈ·ÈÏÓû§Éí·Ý¡£
µÚÒ»²½ÊÇ×öÒ»¸öµÇ¼µÄÒ³Ãæ¡£
µÚ¶þ²½¿ªÊ¼µÇ¼ºóµÄÈ·ÈϳÌÐòµÄÉ ......

php´úÂëÓÅ»¯

 ÏÂÃæÕâһС¶Î“ÁÓÖÊ”µÄPHP´úÂëÊÇÒ»µÀ¼ò»¯Á˵IJâÊÔÌâ¡£ÕâÖÖÎÊÌâ¾ÍÏñÔÚÎÊ£ºÄã¸ÃÔõÑùÓÅ»¯Õâ¶Î´úÂ룿
<?
echo(”<p>Search results for query: ” .
    $_GET['query'] . “.</p>”);
?>
¡¡¡¡Õâ¶Î´úÂëµÄÖ÷ÒªÎÊÌâÔÚÓÚËü°ÑÓû§Ìá½»µÄÊý¾ÝÖ±½ÓÏÔʾµ½ ......

PHPÖÐstr_replaceº¯ÊýʹÓÃС½á

 Õâ¶Îʱ¼äÔÚ¿´¡¶PHPºÍMySQL Web¿ª·¢¡·Ò»Êé¿´µ½str_replace½²½â£¬Ò»¶ÎСÌáʾдµ½£º¿ÉÒÔΪstr_replaceµÄÈý¸ö¶¼Ê¹ÓÃÊý×é´«È룬µ«½²½â±È½Ï¼òµ¥£¬ÓÚÊǾö¶¨×Ô¼ºµÄÊÔÑéһϸú¯ÊýÔÚ¸÷¸ö²ÎÊý´«ÈëÊý×éʱµÄÖ´Ðнá¹û¡£
º¯ÊýÔ­ÐÍ£ºmixed str_replace(mixed needle,mixed new_needle,mixed haystack[,int &count]);
needle£ ......

Php²É¼¯ÈÃÄãµÄÕ¾¸úÐÂÀËÍøµÄÐÂÎű£³Öͬ²½.doc

   ²É¼¯ÒѾ­²»ÊÇʲôÐÂÃû´ÊÁË,ºÜ¶àÕ¾³¤ÎªÁËÊ¡ÊÂ,Ò²¾ÖÏÞÓÚÈËÁ¦µÄȱ·¦,ʹÓóÌÐòÀ´¸ø×Ô¼º
µÄÍøÕ¾Ìíש¼ÓÍß,±ÈÈç±¾È˵ĸöÈËÍøÕ¾Î÷Î÷¸¥Ë¹ÍøÒ²²É¼¯ÁË´óÁ¿µÄÐÂÎÅ,ÄÇôÈç¹ûʵÏÖÄØ?½ñÌìÎÒÃÇÔËÓÃphpÀ´ÊµÏÖÕâ¸ö¹¦ÄÜ.
   ̸µ½²É¼¯,ÎÒÃDz»µÃ²»ËµÁ½¸ö¶«Î÷,µÚÒ»¸öÊÇÈçºÎ»ñÈ¡Ô¶³ÌÍøÕ¾µÄÔ´´úÂë,Õâ¸ö¿ÉÒÔͨ¹ýphpµÄÒ»¸öÀ© ......

PHPÖÐSession±äÁ¿²»ÄÜ´«Ë͵½ÏÂÒ»Ò³µÄ½â¾ö·½·¨

ÔÚPHPÖÐʹÓùýSESSIONµÄÅóÓÑ¿ÉÄÜ»áÅöµ½Õâôһ¸öÎÊÌ⣬SESSION±äÁ¿²»ÄÜ¿çÒ³´«µÝ¡£ÕâÁîÎÒ¿àÄÕÁ˺ÃЩÈÕ×Ó£¬×îÖÕͨ¹ý²é×ÊÁÏ˼¿¼²¢½â¾öÁËÕâ¸öÎÊÌâ¡£ÎÒÈÏΪ£¬³öÏÖÕâ¸öÎÊÌâµÄÔ­ÒòÓÐÒÔϼ¸µã£º
1¡¢¿Í»§¶Ë½ûÓÃÁËcookie
2¡¢ä¯ÀÀÆ÷³öÏÖÎÊÌ⣬ÔÝʱÎÞ·¨´æÈ¡cookie
3¡¢php.iniÖеÄsession.use_trans_sid = 0»òÕß±àÒëʱûÓдò¿ª--enable ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ