Skip to content

Instantly share code, notes, and snippets.

@igorosabel
igorosabel / shorten_url.php
Created February 23, 2011 12:15
Funcion para acortar urls usando el servicio de Google goo.gl
<?php
function shortenUrl($longUrl){
if(!function_exists('curl_init')) {
die ("Curl PHP package not installed\n");
}
$BASEURL = "https://www.googleapis.com/urlshortener/";
$VERSION = "v1";
$SERVICE = "url";
$CONTENT_TYPE = "Content-Type: application/json";
@igorosabel
igorosabel / _json_encode.php
Created November 13, 2014 12:50
Función igual a json_encode, para usar en php < 5.2
function _json_encode( $data ) {
if( is_array($data) || is_object($data) ) {
$islist = is_array($data) && ( empty($data) || array_keys($data) === range(0,count($data)-1) );
if( $islist ) {
$json = '[' . implode(',', array_map('__json_encode', $data) ) . ']';
} else {
$items = Array();
foreach( $data as $key => $value ) {
$items[] = __json_encode("$key") . ':' . __json_encode($value);