<?php
$s = 'LA VIE EST BELLE';
$nb = 0;
for ($i=0; $i < strlen($d); $i++) {
if ( $s[ $i ] != ' ') $nb++;
}
?>
@+
<?php
$string = "la vie est belle" ;
$tok1=str_split($string);
$i=0;
foreach ($tok1 as $string)
{
$i++;
utf8_decode ($string ) ;
$string = preg_replace('/[\s]+/','<br />',$string);
$string = rtrim($string);
echo "$i $string ";
$str = strtok( $string, " \n\t\r");
}
?>
voila pour l'instant sa me le sort comme poster dans mon premier post
function attribuerToken($chaine){
$chaineTab = explode(' ', $chaine);
$token = 0;
foreach($chaineTab as $mot){
$token++;
$tabRes[] = array($mot, $token);
for($i=0; $i<strlen($mot); $i++){
$token++;
$tabRes[] = array($mot{$i}, $token);
}
}
return $tabRes;
}
@+echo lafonction(); a la fin du script et là j ai des erreur:Code : Tout sélectionner
$chaine ="la vie est belle";
la fonctionquivabien($chaine);
etc...
echo lafonctionquivabien();
<?php
function attribuerToken($chaine){
$chaineTab = explode(' ', $chaine);
$token = 0;
foreach($chaineTab as $mot){
$token++;
$tabRes[] = array($mot, $token);
for($i=0; $i<strlen($mot); $i++){
$token++;
$tabRes[] = array($mot{$i}, $token);
}
}
return $tabRes;
}
$chaine ="la vie est belle";
$ret = attribuerToken($chaine);
var_dump($ret);
?>
bon pas testé mais voila ce que tu peux en faire
$result=explode(".",$string);
$exclam=array();
$interro=array();
$str="";$i=0;$total=count($result);
for($i=0;$i<$total;$i++){
$exclam[$i]=explode("!",$result[$i]);
}
$i=0;$total=count($exclam);
for($i=0;$i<$total;$i++){
$interro[$i]=explode("?",$exclam[$i]);
}$total=count($interro);
for($i=0;$i<$total;$i++){echo $interro[$i]."<br/>";
}] mais j ai des erreur et sa fait un peu beaucoup d 'explode