Chasser le cafard - Bug fight

Posted Wednesday, March 23, 2005

Filed under:

Contrairement a ce que vous pourrier croire, je n'ai pas decide de vivre sainement -au contraire diront certains!
J'ai galéré sur un problème très étonnant pendant deux jours et je voulais mettre la solution ici pour que si jamais par hasard quelqu'un tombe dessus...
Des que je veux afficher un gravatar, j'appelle une fonction nommée gravatar (étonnant, non?) et qui prend une adresse mail pour argument. Cette fonction va encoder l'email et afficher le gravatar. Mais c'est là que ca se complique... Au début j'utilisait echo "img" par ignorance du mécanisme réel des fonctions, et le code en question se faisait afficher aussitôt; cette fonction étant appelée pour être intégrée à une chaîne l'ordre d'apparition se trouvait donc perturbé et mes "img" n'étaient pas dans leur conteneur.
La solution: faire retourner le résultat de la fonction à l'aide de return et tout rentre dans l'ordre.
De l'intérêt de lire le manuel...

Unlike what you might infer from the title of this post, I have not yet decided to cast my gloom away -quite the opposite as some would say! I will instead explain what PHP problem I faced and what answer it finally found, in case somebody in need might stumble upon this.
To implement gravatars in this blog I created a function called gravatar (quite appropriate isn't it?) and called it from wherever I wanted. This function takes an email as parameter and outputs a gravatar link. Yet, there was a little problem whit this: I used the usual echo to get the gravatar link, but since the function output was supposed to be buffered the link showed instantly and thus escaped from its legitimate container -choking the parser as it did so.
What solved this problem: using the proper command (return) instead of echo. Well, reading the manual sure can save lots of time...

Comments disabled because of spammers.

No comments yet

Technorati Profile