View Single Post
ישן 31-05-08, 21:53   # 8
fulsyp
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Jul 2007
הודעות: 77

fulsyp לא מחובר  

יש כמה דרכים או להחזיר ערך מהפונקציה לדוגמא לתוך משתנה ככה:
PHP קוד:
function image() {
    
header ("Content-type: image/png");
    
$string substr(md5(time()), 0,5); 
    
$font 5;
    
$width 60;
    
$height 22;
    
$im = @imagecreate ($width,$height);
    
$background_color imagecolorallocate ($im224224224);
    
$text_color imagecolorallocate($im25500);
    
imagestring ($im$font75,$string$text_color);
    
imagepng ($im);
    return 
$string;
}
$image image(); 
או לעשות משתנה גלובאלי...
PHP קוד:
$image "";
function 
image() {
    global 
$image;
    
header ("Content-type: image/png");
    
$string substr(md5(time()), 0,5); 
    
$font 5;
    
$width 60;
    
$height 22;
    
$im = @imagecreate ($width,$height);
    
$background_color imagecolorallocate ($im224224224);
    
$text_color imagecolorallocate($im25500);
    
imagestring ($im$font75,$string$text_color);
    
imagepng ($im);
    
$image $string;

וככה זה ישמור לך אותו
יש עוד דרכים כמו לקבל פרמטר בפונקציה עם & אבל זה יסבך אותך בתור התחלה...
אני משתמש בד"כ בשיטה הראשונה שהצגתי היא הכי נוחה ומסודרת
  Reply With Quote