lui c'est la cerise, faut se faire un peu plaisir des fois

iwannabeamaki (./17) :C'est absolument faux !
Le souci, c'est que potentiellement tu peux avoir un caractère codé sur 3 octets dont les deux derniers sont les mêmes que les 2 octets qui servent à coder un '§', d'où un faux positif : tu vas couper un caractère UTF-8 en deux, et produire un résultat totalement invalide. C'est peu probable, mais ça peut arriver.
iwannabeamaki (./19) :Au contraire, c'est très bien ! (cf. le point précédent ^^)spa bien l'utf8 ?
Ben si mais pas pour le code source(déjà t'aurais pu choisir un caractère ASCII pour tes tags, parceque là c'est vraiment chercher les ennuis ^^)
Non, faut juste coder proprement et arrêter d'essayer de parser une chaine UTF-8 avec une fonction non-UTF-8 pour gagner 3 poulièmes de secondes. Si tu voulais faire un truc rapide, fallait déjà pas choisir PHPEn l'occurrence, c'est parfaitement adapté. (cf le premier point toujours)
echo sredisHashFill(redisPrefix.':prdlist', 'design-produit-thumb', function($w,$d,$n)
{ switch($w)
{ case 'img': return '[url]images/'.$d['ref'].'/'.$d['ref'].'.1.200.jpg'; break;
case 'prix': case 'nom': case 'ref': return $d[$w]; break;
default: return ''; break;
}
}, redisPrefix.':prd:','',function($k,$key,$nb,$nbok)
{ global $curprdref;
if($nbok >= 10 || strpos($k,':') || $k == $curprdref) return 0;
return 1;
},'shuffle');
<?php
global $curprdref; $curprdref = getUrlPath();
echo srandRedisHashFill(redisPrefix.':prdlist','design-produit-mod-left',function($w,$d)
{ switch($w)
{ case 'img': return '[url]images/'.$d['ref'].'/'.$d['ref'].'.1.200.jpg'; break;
case 'prix': case 'nom': case 'ref': return $d[$w]; break;
default: return ''; break;
}
},redisPrefix.':prd:','',function($k,$key)
{ global $curprdref;
return !($k == $curprdref || strpos($k,':'));
});
noDesignCache();
?>
foreach($data as $dta)
{ $out .= str_replace(array_map(function($w){return '$'.$w.'$';},$keywords),array_map(function($w)use($callback,$dta,$n){return $callback($w,$dta,$n);},$keywords),$design);
$n++;
}
[nosmile]<?php
$data = array (
0 =>
array (
'nom' => 'Love Me Body',
'ref' => '8705body..',
'prix' => '31.00',
'txt' => 'Un body plein d\'érotisme en dentelle rouge...',
'img' => '2',
),
1 =>
array (
'prix' => '31.00',
'img' => '2',
'ref' => '0303body..',
'txt' => 'Tout en charme ce body avec ses liserets fushia sur résille noire...',
'nom' => 'Heart Body',
),
2 =>
array (
'prix' => '31.00',
'img' => '2',
'ref' => '8662body..',
'txt' => 'Captivant body noir, idéal pour une soirée coquine a deux. Le tour de la ceinture est agrémenté de zircons chatoyants, ainsi qu\'une broche sertie de pierres brillantes sur le buste.',
'nom' => 'Forget Me Not Body',
),
3 =>
array (
'nom' => 'Combinaison bodystocking Lingerie',
'ref' => 'CR3237body..',
'prix' => '19.99',
'txt' => 'Plus qu\'un simple bodystocking, presqu\'une seconde peau !',
'img' => '2',
),
4 =>
array (
'prix' => '27.99',
'img' => '2',
'ref' => 'CR3167body',
'txt' => 'Ensemble très sexy comprenant une guepière à manches longues avec un ruban permettant de cintrer la taille, incluant porte-jarretelles réglable et son string assorti.
Couleur : Rose
Tailles disponibles : SM ou LXL
Matière : 85% Polyestere, 15% Elastane',
'nom' => 'Guepière filet Rose',
),
5 =>
array (
'nom' => 'Combinaison bodystocking',
'ref' => '7010-BLKBODY',
'prix' => '19.99',
'txt' => 'Combinaison bodystocking noir...',
'img' => '2',
),
6 =>
array (
'prix' => '40.00',
'img' => '2',
'ref' => 'CR3229body',
'txt' => 'Ensemble top et pantalon en dentelle transparente, ultra sexy, ultra glamour....',
'nom' => 'Bodystocking 2 pièces',
),
7 =>
array (
'prix' => '15.99',
'img' => '2',
'ref' => 'CR3243body..',
'txt' => 'Combinaison bodystocking avec ouverture a l\'entre-jambe.
Taille : S/M
Livré en boite rigide.',
'nom' => 'Combinaison bodystocking',
),
8 =>
array (
'prix' => '24.99',
'img' => '1',
'ref' => 'CR3093body',
'txt' => 'Body noir tres envoutant, a dentelle et volant sur le devant et resille au dos, avec bretelles rehausse de petits flots et fentes sur la poitrine et a l\'arriere.',
'nom' => 'Body dentelle ouvert',
),
9 =>
array (
'nom' => 'clean',
'ref' => 'clean',
'prix' => '999',
'txt' => 'bla!',
'img' => '2',
)
);
$keywords = array (
0 => 'ref',
1 => 'nom',
2 => 'nom',
3 => 'img',
4 => 'desc',
5 => 'prix'
);
$callback = function($w,$d,$n)
{ return 'w:'.$w.' n:'.$n;
};
$design='<pre>truc machin chose</pre>';
$tstart = microtime(true);
$iterate = 10000;
while(--$iterate)
{ $arrayin = array_map(function($w){return '$'.$w.'$';},$keywords);
$out=''; $n=0;
reset($data);
foreach($data as $dta)
{ $out .= str_replace($arrayin,array_map(function($w)use($callback,$dta,$n){return $callback($w,$dta,$n);},$keywords),$design);
$n++;
}
}
echo '<br> full array map benchmark : '.round(((microtime(true)-$tstart)*1000),3);
$tstart = microtime(true);
$iterate = 10000;
while(--$iterate)
{ $out=''; $n=0;
$arrayin = array();
array_walk($keywords,function($k)use($arrayin){$arrayin[]='$'.$k.'$';}); // faster
reset($data);
foreach($data as $dta)
{ $arrayout = array();
array_walk($keywords,function($w)use($arrayout,$callback,$dta,$n)
{ $arrayout[] = $callback($w,$dta,$n);
//array_push($arrayout,$callback($w,$dta,$n));
});
$out .= str_replace($arrayin,$arrayout,$design);
$n++;
}
}
echo '<br> full array walk benchmark : '.round(((microtime(true)-$tstart)*1000),3);
$tstart = microtime(true);
$iterate = 10000;
while(--$iterate)
{ $out=''; $n=0;
$arrayin = array();
array_walk($keywords,function($k)use($arrayin){$arrayin[]='$'.$k.'$';}); // faster
//foreach($keywords as $w) $arrayin[]='$'.$k.'$'; // slow!
//foreach($keywords as $w) array_push($arrayin,'$'.$k.'$'); // slower
reset($data);
foreach($data as $dta)
{ $arrayout = array();
reset($keywords); foreach($keywords as $k) $arrayout[] = $callback($w,$dta,$n);
$out .= str_replace($arrayin,$arrayout,$design);
$n++;
}
}
echo '<br> full foreach benchmark : '.round(((microtime(true)-$tstart)*1000),3);
$tstart = microtime(true);
$iterate = 10000;
while(--$iterate)
{ $out=''; $n=0;
$arrayin = array();
array_walk($keywords,function($k)use($arrayin){$arrayin[]='$'.$k.'$';}); // faster
reset($data);
foreach($data as $dta)
{ $out .= str_replace($arrayin,array_map(function($w)use($callback,$dta,$n){return $callback($w,$dta,$n);},$keywords),$design);
$n++;
}
}
echo '<br> best combinaison benchmark : '.round(((microtime(true)-$tstart)*1000),3);
$tstart = microtime(true);
$iterate = 10000;
while(--$iterate)
{ $out=''; $n=0;
$arrayin = array();
array_walk($keywords,function($k)use($arrayin){$arrayin[]='$'.$k.'$';}); // faster
array_walk($data,function($dta)use($callback,$arrayin,$n,$keywords,$out,$design)
{ $out .= str_replace($arrayin,array_map(function($w)use($callback,$dta,$n){return $callback($w,$dta,$n);},$keywords),$design);
$n++;
});
}
echo '<br> best combinaison benchmark with replacing the foreach with array walk : '.round(((microtime(true)-$tstart)*1000
[/nosmile]full array map benchmark : 2914.525 full array walk benchmark : 3107.557 full foreach benchmark : 10894.946 best combinaison benchmark : 2605.041 best combinaison benchmark with replacing the foreach with array walk : 3053.353
function fillDesign($data, $design, $callback=false)
{ global $nodesigncache; $savenodesign=$nodesigncache; $nodesigncache=0; $design=getDesign($design); $nodesigncache=$savenodesign;
$keywords = array();
$offset=0; // search all keywords in the design
$arrayin = array();
for(;;)
{ $start = strpos($design,'$',$offset);
if($start === false) break;
$off = $start+1;
$end = strpos($design,'$',$off);
if($end === false) break;
$size = $end-$off;
$word = substr($design,$off,$size);
if(!isset($keywords[$word]))
{ $keywords[$word] = $word;
$arrayin[$word] = '$'.$word.'$';
} $offset = $end+1;
}
$out = '';
if($callback !== false)
{ $n=0;
if(is_array($callback)) // callback is function array
{ foreach($data as $dta)
{ $out .= str_replace($arrayin,array_map(function($w)use($callback,$dta,$n)
{ if(isset($callback[$w]))
{ if(isset($dta[$w])) return $callback[$w]($dta[$w],$n);
return $callback[$w]($dta,$n);
} else return '';
},$keywords),$design); $n++;
}
}
else
{ // callback is a generic function, who get word and complete data
foreach($data as $dta)
{ $out .= str_replace($arrayin,array_map(function($w)use($callback,$dta,$n){return $callback($w,$dta,$n);},$keywords),$design); $n++;
}
}
} else foreach($data as $dta) $out .= str_replace($arrayin,array_map(function($w)use($dta){if(isset($dta[$w])) return $dta[$w]; return '';},$keywords),$design);
return $out;
}
function needPlugin($plg)
{ $fn = 'fn_'.$plg;
if(function_exists($fn)) return true;
$path = module_path.'/'.$plg.'/'.$plg.'.php';
if(is_file($path)) { include($path); return true; }
return false;
}
function callPlugin($plg,$args)
{ if(false === needPlugin($plg)) return false;
$fn = 'fn_'.$plg;
ob_start(); $fn($args); $out = ob_get_contents(); ob_end_clean();
return $out;
}
[nosmile]<?php
function fn_str($args)
{ print '<pre>'; print_r($args); print '</pre>';
}
function strcut($str, $l=120)
{ if(strlen($str)<$l) return $str; preg_match("/(.{1,$l})\s/u", $str, $match); return $match[1].'...';
if(!needPlugin('str')) die('impossible de charger le plugin "str"');
print strcut('hello fucking world !!! !! :)',10);