<?php
function decode_char($c)
{
$a1 = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "W", "G", "X", "M", "H", "R", "U", "Z", "I", "D", "=", "N", "Q", "V", "B", "L");
$a2 = array("b", "z", "a", "c", "l", "m", "e", "p", "s", "J", "x", "d", "f", "t", "i", "o", "Y", "k", "n", "g", "r", "y", "T", "w", "u", "v");
$result = $c;
for($j = 0; $j < count($a1); $j++) {
if ($c == $a1[$j][0]) {
$result = $a2[$j][0];
break;
}
if ($c == $a2[$j][0]) {
$result = $a1[$j][0];
break;
}
}
return $result;
}
function encode_str($s)
{
$s = base64_encode($s);
$result = '';
for($i = 0; $i < strlen($s); $i++) {
$result .= decode_char($s[$i]);
}
return $result;
}
function decode_str($s)
{
$r = '';
for ($i = 0; $i < strlen($s); $i++){
$r .= decode_char($s[$i]);
}
$r = base64_decode($r);
return $r;
}
$a = encode_str('test');
echo($a."\n");
echo(decode_str($a)."\n");
var result = encodeURIComponent('кодированный текст here');
alert(result);
alert(decodeURIComponent(result));
var result = $.base64.encode(encodeURIComponent("вот такой вот метод кодирования\nраз, два, три!"));
result = result.replace(/[\+]{1}/g, '@').replace(/[\=]{1}/g, '~').replace(/[\/]{1}/g, '$');
console.log(result);
result = result.replace(/[\@]{1}/g, '+').replace(/[\~]{1}/g, '=').replace(/[\$]{1}/g, '/');
console.log(result)
console.log(decodeURIComponent($.base64.decode(result)));
Измененный вид Base64:
JUQwJUIyJUQwJUJFJUQxJTgyJTIwJUQxJTgyJUQwJUIwJUQwJUJBJUQwJUJFJUQwJUI5JTIwJUQwJUIyJUQwJUJFJUQxJTgyJTIwJUQwJUJDJUQwJUI1JUQxJTgyJUQwJUJFJUQwJUI0JTIwJUQwJUJBJUQwJUJFJUQwJUI0JUQwJUI4JUQxJTgwJUQwJUJFJUQwJUIyJUQwJUIwJUQwJUJEJUQwJUI4JUQxJThGJTBBJUQxJTgwJUQwJUIwJUQwJUI3JTJDJTIwJUQwJUI0JUQwJUIyJUQwJUIwJTJDJTIwJUQxJTgyJUQxJTgwJUQwJUI4IQ~~
Возвращаем нормальный вид Base64:
JUQwJUIyJUQwJUJFJUQxJTgyJTIwJUQxJTgyJUQwJUIwJUQwJUJBJUQwJUJFJUQwJUI5JTIwJUQwJUIyJUQwJUJFJUQxJTgyJTIwJUQwJUJDJUQwJUI1JUQxJTgyJUQwJUJFJUQwJUI0JTIwJUQwJUJBJUQwJUJFJUQwJUI0JUQwJUI4JUQxJTgwJUQwJUJFJUQwJUIyJUQwJUIwJUQwJUJEJUQwJUI4JUQxJThGJTBBJUQxJTgwJUQwJUIwJUQwJUI3JTJDJTIwJUQwJUI0JUQwJUIyJUQwJUIwJTJDJTIwJUQxJTgyJUQxJTgwJUQwJUI4IQ==
Декодируем Base64:
вот такой вот метод кодирования
раз, два, три!
$json = 'ваш json';
$array = json_decode($json);
$array = $array['channel_type']['1']['schedule'];
function comparator($one, $two)
{
$one_time = strtotime($one['start']);
$two_time = strtotime($two['start']);
if($one_time == $two_time)
{
return 0;
}
return ($one_time < $two_time) ? -1 : 1;
}
uasort($array, 'comparator');
$('.link').on('click', function(){
$.ajax({
url: 'count.php',
type: 'post',
data: {pres: 'value'},
success: function(response){
console.log(response);
}
});
return false;
})
строка состоящая из нескольких get параметров
$s = 'adfdf=1123&url=http://cs541207v4.vk.me/u63235608/videos/abbe4bbcd0.720.mp4?extra=qxzgmY36um2vOm3XmmutORuGfjwo__AWURSQcoEHnUn8BE54fPVJICkTDFpLfQ3SIdYn-nRUqjtlHo6R8brKHjZ3ChfTcY3x&c=3';
function parse($s)
{
$res = array();
foreach (explode('&',$s) as $tmp)
{
$tmp2 = explode('=',$tmp);
$key = $tmp2[0];
unset ($tmp2[0]);
$res[$key]=implode('=',$tmp2);
}
return $res;
}