Commit 294bc20c by sn

Erweiterungen: mcArray, mcD, service/serialize.php

1 parent ada06a3b
...@@ -168,7 +168,7 @@ class D { ...@@ -168,7 +168,7 @@ class D {
* @param type $param_force * @param type $param_force
* @param type $param_htmlentities * @param type $param_htmlentities
*/ */
public static function s($param_val, $param_string="", $param_loglevel=4, $param_print=true, $param_force=false, $param_htmlentities=false) { public static function s($param_val, $param_string="", $param_loglevel=5, $param_print=true, $param_force=false, $param_htmlentities=false) {
D::show($param_val, $param_string, $param_print, $param_force, $param_htmlentities, $param_loglevel); D::show($param_val, $param_string, $param_print, $param_force, $param_htmlentities, $param_loglevel);
} }
...@@ -188,7 +188,7 @@ class D { ...@@ -188,7 +188,7 @@ class D {
// self::new_echo("<b>show(".$param_string.")</b>", $param_print, $param_force); // self::new_echo("<b>show(".$param_string.")</b>", $param_print, $param_force);
$string_show = "<br /><b>show(".$param_string.")</b><br />"; $string_show = "<br /><b>show(".$param_string.")</b> $param_val<br />";
if($param_loglevel>1) { if($param_loglevel>1) {
if(is_object($param_val) && get_class($param_val)=='DOMElement') { if(is_object($param_val) && get_class($param_val)=='DOMElement') {
D::showdomelement($param_val, $string_show.$param_string,$param_print, $param_force); D::showdomelement($param_val, $string_show.$param_string,$param_print, $param_force);
...@@ -240,6 +240,8 @@ class D { ...@@ -240,6 +240,8 @@ class D {
} }
} }
} else {
$result = $param_val;
} }
} }
} }
...@@ -339,17 +341,17 @@ class D { ...@@ -339,17 +341,17 @@ class D {
/** /**
* *
* @param type $param_Array * @param type $param_Array
* @param string $param_Print * @param string $param_string
* @param type $param_logdepth * @param type $param_logdepth
* @param type $param_ul * @param type $param_ul
* @param type $param_keystring * @param type $param_keystring
*/ */
public static function fe($param_Array, $param_Print=null, $param_logdepth=10, $param_ul=array(), $param_keystring='') { public static function fe($param_Array, $param_string=null, $param_logdepth=10, $param_ul=array(), $param_keystring='', $param_print=true, $param_force=false) {
// D::ulli(':::::::::::::: '.$param_logdepth.' - '.$param_Array); // D::ulli(':::::::::::::: '.$param_logdepth.' - '.$param_Array);
if($param_logdepth>=0) { if($param_logdepth>=0) {
if(!is_null($param_Print)) { if(!is_null($param_string)) {
$param_Print .= ' count('.count($param_Array).') loglevel('.$param_logdepth.') || print '.$param_Array; $param_string .= ' count('.count($param_Array).') loglevel('.$param_logdepth.') || print '.$param_Array;
D::li($param_Print); D::li($param_string, $param_print, $param_force);
} }
$param_logdepth--; $param_logdepth--;
$param_ul['start'] .= '<ul>'; $param_ul['start'] .= '<ul>';
...@@ -377,10 +379,10 @@ class D { ...@@ -377,10 +379,10 @@ class D {
$var_value2Array = $param_Array; $var_value2Array = $param_Array;
} }
self::new_echo($param_ul['start'].'<li>'.$param_keystring.' => '.$param_Array.' '.$info_toArray.' </li>'.$param_ul['stop']); self::new_echo($param_ul['start'].'<li>'.$param_keystring.' => '.$param_Array.' '.$info_toArray.' </li>'.$param_ul['stop'], $param_print, $param_force);
if(is_array($var_value2Array)) { if(is_array($var_value2Array)) {
foreach($var_value2Array as $var_key => $var_value) { foreach($var_value2Array as $var_key => $var_value) {
D::fe($var_value, null, $param_logdepth, $param_ul,$var_key); D::fe($var_value, null, $param_logdepth, $param_ul,$var_key, $param_print, $param_force);
} }
} }
} }
......
...@@ -10,6 +10,11 @@ class mcArray { ...@@ -10,6 +10,11 @@ class mcArray {
const ARRAY_MIDDLE = '1M1'; const ARRAY_MIDDLE = '1M1';
const ARRAY_START = '1S1'; const ARRAY_START = '1S1';
const ARRAY_STOP = '1E1'; const ARRAY_STOP = '1E1';
/** /**
* transform a array to a string ... in example for SEOLink * transform a array to a string ... in example for SEOLink
* *
...@@ -108,12 +113,97 @@ class mcArray { ...@@ -108,12 +113,97 @@ class mcArray {
} }
/**
*
*
*
* @param array $param_PathAsArray => example: array(key1, key2, key3, key4, value)
* @param array $param_ResultArray => example: array[key1][key2][key3][key4] = value --
* Achtung da die Funktion array_merge_recursive genutzt wird, ergeben sich komische Effekte bein integer keys
* array_merge_recursive wird nur genutzt beim $param_ResultArray - im Zweifel mcArray::putIntKeyPathValueToArray nutzen
*
* @return array zusammengeführtes Arry vom neuen generierten Array aus $param_PathAsArray und param_ResultArray
Array(
[key1] => Array
(
[key2] => Array
(
[keyA] => Array
(
[keyB] => value
)
[key3] => Array
(
[key4] => value
)
)
)
)
*
*
*/
public static function putStringKeyPathValueToArray(array $param_PathAsArray, $param_ResultArray=array()) {
$new_array = array();
$firstkey = array_shift($param_PathAsArray);
// $firstkey = (string)'_'.$firstkey."_";
$firstkey = (string) ''.$firstkey."";
$new_array[$firstkey] = array();
if(count($param_PathAsArray) == 1) {
$new_array[$firstkey] = array_shift($param_PathAsArray);
} else {
$new_array[$firstkey] = mcArray::putStringKeyPathValueToArray($param_PathAsArray);
}
if(!empty($param_ResultArray)) {
$result_array = array_merge_recursive($param_ResultArray, $new_array);
} else {
$result_array = $new_array;
}
return $result_array;
}
/**
* analog zu mcArray::putStringKeyPathValueToArray nur auch mit Int Key möglich
*
* @param array $param_PathAsArray
* @param type $param_ResultArray
* @return type
*/
public static function putIntKeyPathValueToArray(array $param_PathAsArray, $param_ResultArray=array()) {
// $new_array = array();
$firstkey = array_shift($param_PathAsArray);
$firstkey = (string)''.$firstkey."";
if(!array_key_exists($firstkey, $param_ResultArray)) {
$param_ResultArray[$firstkey] = array();
}
if(count($param_PathAsArray) == 1) {
$param_ResultArray[$firstkey] = array_shift($param_PathAsArray);
} else {
$param_ResultArray[$firstkey] = mcArray::putIntKeyPathValueToArray($param_PathAsArray, $param_ResultArray[$firstkey]);
}
return $param_ResultArray;
}
/**
* Gegenstück zu self::putKeyPathValueToArray()
*
* @param array $param_PathAsArray => example: array(key1, key2, key3, key4)
* @param array $param_Array => example: self::putKeyPathValueToArray()
* @return boolean
*/
public static function returnValueFromKeyPath(array $param_PathAsArray, array $param_Array) { public static function returnValueFromKeyPath(array $param_PathAsArray, array $param_Array) {
$searcharray = $param_Array; $searcharray = $param_Array;
foreach($param_PathAsArray as $key) { foreach($param_PathAsArray as $key) {
if(is_array($searcharray)) { if(is_array($searcharray)) {
if(array_key_exists($key, $searcharray)) { if(array_key_exists($key, $searcharray)) {
$searcharray = $searcharray[$key]; $searcharray = $searcharray[$key];
} else {
return false;
} }
} else { } else {
return false; return false;
...@@ -127,7 +217,7 @@ class mcArray { ...@@ -127,7 +217,7 @@ class mcArray {
* transformiert Array mit speziellen String Key zu einem normalen Key * transformiert Array mit speziellen String Key zu einem normalen Key
* *
* @param array param_Array -- Array welches transformiert wird * @param array param_Array -- Array welches transformiert wird
* @param string param_pattern -- Pattern für den Schlüssel (im Beispiel '_#_') * @param string param_pattern -- Pattern für den Schlüssel (im Beispiel '_#_') (darf nicht zB -+- sein)
* *
* Array * Array
( (
...@@ -183,7 +273,7 @@ class mcArray { ...@@ -183,7 +273,7 @@ class mcArray {
$tmp_POST[$post_key][$i+1] =& $tmp_POST[$post_key][$i][$array_key[$i]]; $tmp_POST[$post_key][$i+1] =& $tmp_POST[$post_key][$i][$array_key[$i]];
} }
} }
//D::show($tmp_POST[$post_key][0], '$tmp_POST['.$post_key.'][0]');
mcArray::addArrayValueToArray($param_Array, $tmp_POST[$post_key][0]); mcArray::addArrayValueToArray($param_Array, $tmp_POST[$post_key][0]);
unset($param_Array[$post_key]); unset($param_Array[$post_key]);
......
<?php
if(array_key_exists('not_serialize', $_POST)) {
$serialize_s = serialize($_POST['not_serialize']);
$not_serialize_s = $_POST['not_serialize'];
} else {
$serialize_s = $not_serialize_s= '';
}
if(array_key_exists('serialize', $_POST)) {
$serialize_us = unserialize($_POST['serialize']);
$not_serialize_us = $_POST['serialize'];
} else {
$serialize_us = $not_serialize_us= '';
}
?>
<html>
<head><title></title></head>
<body>
<form action="serialize.php" method="post">
<h2>Klartext serilisieren</h2>
<p><textarea name="not_serialize" cols="50" rows="10"><?php echo $not_serialize_s ?></textarea></p>
<p><?php echo $serialize_s ?></p>
<h2>serilisierte Text zu Klartext</h2>
<p><textarea name="serialize" cols="50" rows="10"><?php echo $not_serialize_us ?></textarea></p>
<p><pre><?php echo print_r($serialize_us, true) ?></pre></p>
<input type="submit" value=" Absenden ">
<input type="reset" value=" Abbrechen">
</form>
</body>
</html>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!