Précédent   Forum des professionnels en informatique > PHP > Langage > Fonctions
Fonctions Forum d'entraide sur les fonctions PHP. Avant de poster -> FAQ fonctions et Sources diverses
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 08/09/2011, 17h47   #1
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

Informations professionnelles :
Activité : Développeur Web
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Par défaut Call to undefined function money_format()

Bonjour,
J’essaie ce code :
Code :
1
2
3
4
5
6
 
$number = 1234.56;
 
// Affichons ce nombre au format international pour en_US
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
et j'ai comme message d'erreur :
Citation:
Fatal error: Call to undefined function money_format() in I:\wamp\www\money\index.php on line 7
et
Code :
1
2
3
 
//line 7
echo money_format('%i', $number) . "\n";
Pourquoi cette erreur?

NB. Je suis sous wampserver 2.0 avec PHP 5.3.0

Merci d'avance...
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/09/2011, 17h54   #2
Modérateur
 
Avatar de Benjamin Delespierre
 
Benjamin Delespierre
Développeur Web
Inscription : février 2010
Messages : 2 991
Détails du profil
Informations personnelles :
Nom : Benjamin Delespierre
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : février 2010
Messages : 2 991
Points : 5 032
Points : 5 032
Comme mentionné dans la doc, cette fonction n'est pas disponible sous Windows:
Citation:
The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.
__________________
A la recherche d'un framework MVC facile a prendre en main ? Essayez Axiom
Nouveau: la référence d'Axiom est disponible sur GitHub (je la peaufine en ce moment même).

Un problème correctement identifié est à moitié résolu, évitez de poster l'intégralité de votre code avec pour seule explication "ça ne marche pas...".
Pour identifier correctement vos problèmes PHP, utilisez la gestion des erreurs et xdebug.

Les boutons et existent, servez-vous en
Benjamin Delespierre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/09/2011, 17h58   #3
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

Informations professionnelles :
Activité : Développeur Web
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Comment simuler donc cette fonction sous windows :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
/*
 * Formater un nombre pour l'afficher comme un prix avec une devise
 *
 * @param float $prix Valeur du prix Ã* formater
 * @return string Retourne une chaine contenant le prix formaté avec une devise (par défaut l'euro)
 */
function prix_formater($prix){
 
    // Pouvoir débrayer la devise de référence
    if (! defined('PRIX_DEVISE')) {
        define('PRIX_DEVISE','fr_FR.utf8');
    }
 
    setlocale(LC_MONETARY, PRIX_DEVISE); 
 
    $prix = money_format('%i', $prix); 
 
    // Afficher la devise € si celle ci n'est pas remontée par la fonction money
    if (money_format('%#1.0n', 0) == 0) 
        $prix .= ' €'; 
 
    return $prix;
}
Merci d'avance...
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/09/2011, 18h28   #4
Modératrice
 
Avatar de Celira
 
Femme
Développeuse PHP/Java
Inscription : avril 2007
Messages : 3 661
Détails du profil
Informations personnelles :
Sexe : Femme
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeuse PHP/Java

Informations forums :
Inscription : avril 2007
Messages : 3 661
Points : 5 388
Points : 5 388
Il faut implémenter money_format toi-même. Hereusement dans ce genre de cas, on trouve souvent des fonctions alternatives dans les commentaires de la doc.
http://www.php.net/manual/fr/functio...rmat.php#89060
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
That it is an implementation of the function money_format for the
platforms that do not it bear. 
 
The function accepts to same string of format accepts for the
original function of the PHP. 
 
(Sorry. my writing in English is very bad) 
 
The function is tested using PHP 5.1.4 in Windows XP
and Apache WebServer.
*/
function money_format($format, $number)
{
    $regex  = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?'.
              '(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/';
    if (setlocale(LC_MONETARY, 0) == 'C') {
        setlocale(LC_MONETARY, '');
    }
    $locale = localeconv();
    preg_match_all($regex, $format, $matches, PREG_SET_ORDER);
    foreach ($matches as $fmatch) {
        $value = floatval($number);
        $flags = array(
            'fillchar'  => preg_match('/\=(.)/', $fmatch[1], $match) ?
                           $match[1] : ' ',
            'nogroup'   => preg_match('/\^/', $fmatch[1]) > 0,
            'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ?
                           $match[0] : '+',
            'nosimbol'  => preg_match('/\!/', $fmatch[1]) > 0,
            'isleft'    => preg_match('/\-/', $fmatch[1]) > 0
        );
        $width      = trim($fmatch[2]) ? (int)$fmatch[2] : 0;
        $left       = trim($fmatch[3]) ? (int)$fmatch[3] : 0;
        $right      = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits'];
        $conversion = $fmatch[5];
 
        $positive = true;
        if ($value < 0) {
            $positive = false;
            $value  *= -1;
        }
        $letter = $positive ? 'p' : 'n';
 
        $prefix = $suffix = $cprefix = $csuffix = $signal = '';
 
        $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign'];
        switch (true) {
            case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+':
                $prefix = $signal;
                break;
            case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+':
                $suffix = $signal;
                break;
            case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+':
                $cprefix = $signal;
                break;
            case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+':
                $csuffix = $signal;
                break;
            case $flags['usesignal'] == '(':
            case $locale["{$letter}_sign_posn"] == 0:
                $prefix = '(';
                $suffix = ')';
                break;
        }
        if (!$flags['nosimbol']) {
            $currency = $cprefix .
                        ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) .
                        $csuffix;
        } else {
            $currency = '';
        }
        $space  = $locale["{$letter}_sep_by_space"] ? ' ' : '';
 
        $value = number_format($value, $right, $locale['mon_decimal_point'],
                 $flags['nogroup'] ? '' : $locale['mon_thousands_sep']);
        $value = @explode($locale['mon_decimal_point'], $value);
 
        $n = strlen($prefix) + strlen($currency) + strlen($value[0]);
        if ($left > 0 && $left > $n) {
            $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0];
        }
        $value = implode($locale['mon_decimal_point'], $value);
        if ($locale["{$letter}_cs_precedes"]) {
            $value = $prefix . $currency . $space . $value . $suffix;
        } else {
            $value = $prefix . $value . $space . $currency . $suffix;
        }
        if ($width > 0) {
            $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ?
                     STR_PAD_RIGHT : STR_PAD_LEFT);
        }
 
        $format = str_replace($fmatch[0], $value, $format);
    }
    return $format;
}
 
?>
__________________
Modératrice PHP
Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)

Pour afficher votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur)
Celira est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/09/2011, 19h00   #5
Modérateur
 
Inscription : septembre 2010
Messages : 7 131
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 131
Points : 8 491
Points : 8 491
Si t'as Intl utilise numfmt_format_currency
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/09/2011, 11h45   #6
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

Informations professionnelles :
Activité : Développeur Web
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Merci à vous tous.
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 20h06.


 
 
 
 
Partenaires

Hébergement Web