<NME> encode.php
<BEF> <?php

//header ("Content-Type:text/xml");
//syslog(LOG_ERR, "message to send to log");

// alfred encode.php test\"\'<é

// ****************

require_once('workflows.php');

$w = new Workflows();
    $data = str_replace(array('+','/','='),array('-','_',''),$data);
    return $data;
{query}
EOD;
}

if (1) {
	echo "".$query."\n";
	echo "urlencode = ".urlencode($query)."\n";
	echo "utf8_encode = ".utf8_encode($query)."\n";
	echo "htmlentities = ".htmlentities($query, ENT_QUOTES, 'UTF-8')."\n";
	echo "base64_encode = ".base64_encode($query)."\n";
	
	exit();
	foreach ($items as $key => $value) {


$encodes = array();
// url
$url_encode = urlencode($query);
if ($url_encode != $query) $encodes["URL Encoded"] = $url_encode;
	}
	return $res;
}
if ($utf8_encode != $query) $encodes["UTF8 Encoded"] = $utf8_encode;

// HTML
$html_encode = htmlentities($query, ENT_QUOTES, 'UTF-8');
if ($html_encode != $query) $encodes["HTML Encoded"] = $html_encode;

//$dencodes["UTF-8 encoded"] = utf8_encode($query);

// base64
$base64_encode = base64_encode($query);
if ($base64_encode != $query) $encodes["base64 Encoded"] = $base64_encode;
	$html_encode = htmlentities($html_encode, ENT_QUOTES, 'UTF-8', false);
	echo " = ".$html_encode."\n";
	echo "base64_encode = ".base64_encode($query)."\n";
	echo "urlsafe_base64_encode = ".urlsafe_b64encode($query)."\n";
	exit();
}


$encodes = array();

// url
$url_encode = urlencode($query);
if ($url_encode != $query) $encodes["URL Encoded"] = $url_encode;

// HTML
/*$html_encode = '';
$table = get_html_translation_table(HTML_ENTITIES);
for ($i = 0, $l = sizeof($chars); $i < $l; $i++) {
	$html_encode .= $table[$chars[$i]] ? $table[$chars[$i]] : $chars[$i];
}
$html_encode = htmlentities($html_encode, ENT_QUOTES, 'UTF-8', false);*/
$html_encode = htmlentities($query, ENT_QUOTES, 'UTF-8');
if ($html_encode != $query) $encodes["HTML Encoded"] = $html_encode;

// unicode
$unicode_encode = preg_replace_callback('/[\x{4e00}-\x{9fa5}]/iu', 'replace_unicode_escape_sequence', $query);
if ($unicode_encode != $query) $encodes["Unicode Encoded"] = $unicode_encode;

// base64
$base64_encode = base64_encode($query);
if ($base64_encode != $query) $encodes["base64 Encoded"] = $base64_encode;

// base64 with urlsafe
$urlsafe_base64_encode = urlsafe_b64encode($query);
if ($urlsafe_base64_encode != $query) $encodes["base64(urlsafe) Encoded"] = $urlsafe_base64_encode;

$encodes = prepare_output($encodes);

foreach($encodes as $key => $value) {
	$w->result( $key, $value, $value, $key, 'icon.png', 'yes' );
}

if ( count( $w->results() ) == 0 ) {
	$w->result( 'encode', $query, 'Nothing useful resulted', 'The encoded strings were the same as your query', 'icon.png', 'yes' );
}

echo $w->toxml();
// ****************
?>

<MSG> 1.5
decode base64 bug fix

<DFF> @@ -7,6 +7,18 @@
 
 // ****************
 
+function str_split_unicode($str, $l = 0) {
+    if ($l > 0) {
+        $ret = array();
+        $len = mb_strlen($str, "UTF-8");
+        for ($i = 0; $i < $len; $i += $l) {
+            $ret[] = mb_substr($str, $i, $l, "UTF-8");
+        }
+        return $ret;
+    }
+    return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
+}
+
 require_once('workflows.php');
 
 $w = new Workflows();
@@ -15,12 +27,21 @@ if (!isset($query)) {
 {query}
 EOD;
 }
+$chars = str_split_unicode($query);
 
-if (1) {
-	echo "".$query."\n";
+if (0) {
+	echo "".$query." - ".implode("", $chars)."\n";
 	echo "urlencode = ".urlencode($query)."\n";
 	echo "utf8_encode = ".utf8_encode($query)."\n";
-	echo "htmlentities = ".htmlentities($query, ENT_QUOTES, 'UTF-8')."\n";
+	echo "htmlentities = ".htmlentities($query, ENT_QUOTES, 'UTF-8', false)."\n";
+	$html_encode = '';
+	$table = get_html_translation_table(HTML_ENTITIES);
+	for ($i = 0, $l = sizeof($chars); $i < $l; $i++) {
+		echo $chars[$i]." -> ".$table[$chars[$i]]."\n";
+		$html_encode .= $table[$chars[$i]] ? $table[$chars[$i]] : $chars[$i];
+	}
+	$html_encode = htmlentities($html_encode, ENT_QUOTES, 'UTF-8', false);
+	echo " = ".$html_encode."\n";
 	echo "base64_encode = ".base64_encode($query)."\n";
 	
 	exit();
@@ -28,6 +49,7 @@ if (1) {
 
 
 $encodes = array();
+
 // url
 $url_encode = urlencode($query);
 if ($url_encode != $query) $encodes["URL Encoded"] = $url_encode;
@@ -37,11 +59,15 @@ $utf8_encode = utf8_encode($query);
 if ($utf8_encode != $query) $encodes["UTF8 Encoded"] = $utf8_encode;
 
 // HTML
-$html_encode = htmlentities($query, ENT_QUOTES, 'UTF-8');
+/*$html_encode = '';
+$table = get_html_translation_table(HTML_ENTITIES);
+for ($i = 0, $l = sizeof($chars); $i < $l; $i++) {
+	$html_encode .= $table[$chars[$i]] ? $table[$chars[$i]] : $chars[$i];
+}
+$html_encode = htmlentities($html_encode, ENT_QUOTES, 'UTF-8', false);*/
+$html_encode = htmlentities($query, ENT_QUOTES, 'UTF-8', false);
 if ($html_encode != $query) $encodes["HTML Encoded"] = $html_encode;
 
-//$dencodes["UTF-8 encoded"] = utf8_encode($query);
-
 // base64
 $base64_encode = base64_encode($query);
 if ($base64_encode != $query) $encodes["base64 Encoded"] = $base64_encode;

1.5 decode base64 bug fix