Skip to content

Instantly share code, notes, and snippets.

<?php
// echo phpinfo();
// Set the content-type
// header('Content-Type: image/png');
header ("Content-type: image/png");
$x = 600;
$y = 1240;
// $x = 240;
@guoxiangke
guoxiangke / preg
Created November 9, 2015 03:09
匹配到最后一个括号里的内容 preg (
[\((][\s\S]*[\))]
@guoxiangke
guoxiangke / README.md
Created December 21, 2015 10:15 — forked from jimothyGator/README.md
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default and default-ssl to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/
@guoxiangke
guoxiangke / add a Cancel button to Drupal forms
Created January 18, 2013 03:42
关键点: '#type' => 'submit', '#limit_validation_errors' => array(), '#submit' => array('yourmodule_cancel_buttons_callback')
/**
* @file
* Defines a Cancel button on node forms
*/
function yourmodule_cancel_form_node_form_alter(&$form, &$form_state) {
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 20,
'#executes_submit_callback' => TRUE,
@guoxiangke
guoxiangke / views_agax
Last active October 23, 2015 09:08
drupal views Ajax get views update
<div id="views">views!!!begin!!!
<?php
print views_embed_view('foodbanks', 'block', $state);
?>
<a href="##" id= "freash" >freash!!!</a>
<script type="text/javascript">
(function($) {
function getInfo(args) {
$.ajax({
@guoxiangke
guoxiangke / Entity metadata wrappers.php
Created October 9, 2012 09:51
Entity metadata wrappers
<?php
// Create wrapper around the node.
$wrapper = entity_metadata_wrapper('node', $node);
// We can do it also using only $nid.
$wrapper = entity_metadata_wrapper('node', $nid);
// Get the value of field_name of the nodes author's profile.
$wrapper->author->profile->field_name->value();
$wrapper->author->profile->field_name->set('New name');
@guoxiangke
guoxiangke / print block in template with contextual-links
Created September 11, 2015 08:49
print block in template with contextual-links 在模板中打印block 带有编辑连接!
@guoxiangke
guoxiangke / Geolocation maxmind
Created September 7, 2015 07:46
Geolocation maxmind
/**
* Geolocation
*/
$ip = $_SERVER['REMOTE_ADDR'];
$result = db_select('ip_geolocation', 'g')
->fields('g')
->condition('ip', $ip, '=')
->execute()
->fetchAssoc();
@guoxiangke
guoxiangke / preg get URL parameter
Created June 30, 2015 03:54
//正则表达式获取URL参数 preg get URL parameter
//正则表达式获取URL参数 preg get URL parameter
//http://stackoverflow.com/questions/11706986/php-getting-url-variable-with-preg-match
$subject = "http://www.mysite.com?id=05&name=johnny";
$pattern = '/id=[0-9A-Za-z]*/'; //$pattern = '/id=[0-9]*/'; if it is only numeric.
preg_match($pattern, $subject, $matches);
print_r($matches);
@guoxiangke
guoxiangke / Multiple cURL Requests with PHP
Created March 17, 2015 08:03
Multiple cURL Requests with PHP
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multiple cURL Requests with PHP</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css">