PHP - fonction qui fonctionne pas
Résolu
nino11
Messages postés
76
Date d'inscription
Statut
Membre
Dernière intervention
-
Artemischasseur Messages postés 36 Date d'inscription Statut Membre Dernière intervention -
Artemischasseur Messages postés 36 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je rencontre des problèmes avec cette fonction que j'ai écrit...
Et je comprends pas pourquoi ...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Test de la fonction insert</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php function insert ($str, $carac, $pos)
{
If (strlen($str)<$pos)
{
$str = $str + $carac;
}
else
{
$temp = $str;
$str = substr($temp, 0, $pos-1) + $carac + substr($temp, $pos);
}
return ($str);
}
?>
</head>
<body>
<?php
$var="rue";
$var2=insert($var, "o", 2);
echo $var2;
?>
</body>
</html>
Je rencontre des problèmes avec cette fonction que j'ai écrit...
Et je comprends pas pourquoi ...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Test de la fonction insert</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php function insert ($str, $carac, $pos)
{
If (strlen($str)<$pos)
{
$str = $str + $carac;
}
else
{
$temp = $str;
$str = substr($temp, 0, $pos-1) + $carac + substr($temp, $pos);
}
return ($str);
}
?>
</head>
<body>
<?php
$var="rue";
$var2=insert($var, "o", 2);
echo $var2;
?>
</body>
</html>
A voir également:
- PHP - fonction qui fonctionne pas
- Fonction si et - Guide
- Easy php - Télécharger - Divers Web & Internet
- Fonction miroir - Guide
- Fonction moyenne excel - Guide
- Expert php pinterest - Télécharger - Langages
Ca m'affiche toujours 0, alors que ça devrais m'afficher "roue"...
En PHP, la concaténation de chaîne s'effectue grâce au point.
Bon, ça marche, par contre faut rajouter un "-1" dans la concaténation dans le "else", à la fin, faut mettre pos-1... enfin, ça marche, merci ^^