<?php

function encode($str) {
	$str = htmlentities($str, ENT_QUOTES, 'UTF-8');
	
	// http://w...content-available-to-author-only...e.com/reference/specialcharacters.php
	$special = array(
		'[' => '&#91;',
		']' => '&#93;',
	);
	$str = str_replace(array_keys($special), array_values($special), $str);
	
	return $str;
}

function decode($str) {
	return html_entity_decode($str, ENT_QUOTES, 'UTF-8');
}

$original = '[1,2,3,"&",{a:1,b:2,"c":"Результат"}]';
$encoded  = encode($original);
$decoded  = decode($encoded);

echo "Original:\t", $original, PHP_EOL;
echo "Shortcode:\t", '[hi abc="'. $encoded .'"]', PHP_EOL;
echo "Decoded:\t", $decoded, PHP_EOL;
echo "Equal:\t\t", ($original === $decoded) ? 'YES' : 'NO';
