PHP 如何轻松访问PHP中的JSON(如具有多个字段的JSON记录集)

<?php

// json is here a field, but can be your input too. This is for educational purposes
// this sample is the output from an Extjs Ajax call, submitting a complete grid back
// to the server

$json = '{
    "success" : "true",
    "message" : "OK",
    "total"   : "3",
    "records" : [
        {
            "se_pkey": "DE",
            "se_langvalue": "Deutsch",
            "se_picon": "de",
            "se_pvalue": "Lehrinstitut",
            "se_pshow": "1",
            "se_id": "216" 
        },
        {
            "se_pkey": "EN",
            "se_langvalue": "Englisch",
            "se_picon": "en",
            "se_pvalue": "Institute",
            "se_pshow": "1",
            "se_id": "227" 
        },
        {
            "se_pkey": "NL",
            "se_langvalue": "Niederl\u00e4ndisch",
            "se_picon": "nl",
            "se_pvalue": null,
            "se_pshow": null,
            "se_id": null 
        } 
    ]
}';

$exjson = json_decode($json, true);  // decode the json string to an array

foreach ( $exjson['records'] as $row ) {  // loop the records

     echo 'To access fields, this works too: '.  $row['se_id']. '<br/>';

     foreach ( $row as $field => $value ) {  // loop the fields

         // $field = field name
         // $row   = record
         // $value = field value

         echo $field . ': '. $value . '<br>';
     }
     echo '<br/>'; 
}

?>

PHP WordPress - 按名称获取帖子或页面ID

function getPageByName($page_name) {
	global $wpdb;
	$page_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
	return $page_name_id;
}

JavaScript JavaScript Set Cookie

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

JavaScript JavaScript Set Cookie Midnight Expiration

function createCookie(name,value,path) {
	var expires = "";
	var date = new Date();
	var midnight = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59);
	expires = "; expires=" + midnight.toGMTString();
	if (!path) {
		path = "/";
	}
	document.cookie = name + "=" + value + expires + "; path=" + path;
}

CSS IE Png修复

#[name]{ 

 
behavior: expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
        this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')",
        this.src = "transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
        this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')",
        this.runtimeStyle.backgroundImage = "none")),this.pngSet=true)
    );
	
	 }

ActionScript 3 AS3修剪逗号分隔字符串(例如,用户输入的逗号分隔关键字列表)

function removeExtraSpacesFromKeywords($keywords:String):String {
	var trimmedKeywords:String;
	var doubleCommaRegExp:RegExp = /,,/gi;
	var doubleSpaceRegExp:RegExp = /  /gi;
	var keywordsArray:Array = $keywords.split(",");
	for (var i=0; i<keywordsArray.length; i++) {
		keywordsArray[i] = keywordsArray[i].replace(/^\s+|\s+$/g, '');
	}
	trimmedKeywords = keywordsArray.toString();
	do {
		trimmedKeywords = trimmedKeywords.replace(doubleCommaRegExp, ",");
	} while (doubleCommaRegExp.test(trimmedKeywords));
	do {
		trimmedKeywords = trimmedKeywords.replace(doubleCommaRegExp, ",");
	} while (doubleCommaRegExp.test(trimmedKeywords));
	do {
		trimmedKeywords = trimmedKeywords.replace(doubleCommaRegExp, ",");
	} while (doubleCommaRegExp.test(trimmedKeywords));
	var firstChar:String = trimmedKeywords.substr(0, 1);
	if (firstChar == ",") {
		trimmedKeywords = trimmedKeywords.substring(1, trimmedKeywords.length);
	}
	var lastChar:String = trimmedKeywords.substr(trimmedKeywords.length-1, 1);
	if (lastChar == ",") {
		trimmedKeywords = trimmedKeywords.substring(0, trimmedKeywords.length-1);
	}
	do {
		trimmedKeywords = trimmedKeywords.replace(doubleSpaceRegExp, " ");
	} while (doubleSpaceRegExp.test(trimmedKeywords));
	do {
		trimmedKeywords = trimmedKeywords.replace(doubleSpaceRegExp, " ");
	} while (doubleSpaceRegExp.test(trimmedKeywords));
	return trimmedKeywords;
}

var keywords:String = ",,,, ,,   ,  one    ,,, ,,, , , ,, ,,,, , ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,  , ,  , ,,,,,,,,,,,,,,,,,,,, ,,,   ,  two     ,     three   ,    hello               world   ,  ,, ,,, ,,,,";
trace(keywords);
keywords = removeExtraSpacesFromKeywords(keywords);
trace(keywords);

// OUTPUT
// ,,,, ,,   ,  one    ,,, ,,, , , ,, ,,,, , ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,  , ,  , ,,,,,,,,,,,,,,,,,,,, ,,,   ,  two     ,     three   ,    hello               world   ,  ,, ,,, ,,,,
// one,two,three,hello world

jQuery 加载页面时的淡化效果

//on top of page											 
$.ajaxSetup ({
    // Disable caching of AJAX responses */
    cache: false
});

//fire jQuery when hitting the back button
history.navigationMode = 'compatible';

//page effects
$("body").css("display", "none");
$("body").fadeIn(1500);
$("a.transition").click(function(event){
  event.preventDefault();
  linkLocation = this.href;
  $("body").fadeOut(500, function() {
    window.location = linkLocation;
  });
});

---

<body onunload=""> <!-- property to fix bfcache for firefox 3.5 -->

JavaScript 抓住Google CDN的jQuery。如有必要,可以回到当地

<!-- Grab Google CDN's jQuery. fall back to local if necessary -->  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>  
<script>!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"></script>')</script>

C# 将字符串编码为字节

private byte[] EncodeMsg(string msg)
        {
            ASCIIEncoding encoder = new ASCIIEncoding();
            byte[] buffer = encoder.GetBytes(msg);

            return buffer;
        }

ActionScript 3 在FlashDevelop中嵌入truetype字体(Flex 4+)

[Embed(source='C:/WINDOWS/Fonts/verdana.ttf', fontFamily="Verdana", fontWeight="regular", embedAsCFF="false")]
public var Verdana:Class;

private var mytextfield:TextField = new TextField();
private var mytextformat:TextFormat = new TextFormat();

/*
... class declaration ...
*/

mytextformat.font = "Verdana";

mytextfield.embedFonts = true;
mytextfield.defaultTextFormat = mytextformat;