הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   htmlspecialchars ומערך (https://hosts.co.il/forums/showthread.php?t=77723)

OrPol 20-08-09 22:07

htmlspecialchars ומערך
 
שלום,
יש לי מערך בשם $buyinfo
השאלה היא אם אני אשתמש בפקודה בצורה הזאת
PHP קוד:

$buyinfo htmlspecialchars($buyinfo); 

אני אקבל את התוצאה על כל המערך?
ואם לא איך כן אוכל? ע"י לולאה?


תודה מראש

mlnn 20-08-09 22:45

לא. כן.
תקרא תגובות במנואל..
http://il2.php.net/htmlspecialchars

Shay Ben Moshe 21-08-09 10:56

Sorry for the english, I just installed Linux.
The solution is to use a foreach loop.
If this is 1d array than you should use a function like this:
PHP קוד:

function ArrSpecialChars($array) {
    foreach(
$array as $key=>$val) {
        
$array[$key] = htmlspecialchars($val);
    }


But, if it is a 2d or more array you should use something recursive like this:
PHP קוד:

function ArrSpecialChars($array) {
    foreach(
$array as $key=>$val) {
        if(
is_array($val)) {
            
$array[$key] = ArrSpecialChars($val);
        }
        
$array[$key] = htmlspecialchars($val);
    }
    return 
$array;


Of cures this one will work for both cases.

Edit:
You can use this function as a master function, for strings to arrays..
PHP קוד:

function SpecialChars($text) {
    if(
is_array($text)) {
        foreach(
$text as $key=>$val) {
            if(
is_array($val)) {
                
$text[$key] = SpecialChars($val);
            }
            
$text[$key] = htmlspecialchars($val);
        }
        return 
$text;
    }
    elseif(
is_string($text)) {
        
$text htmlspecialchars($text);
        return 
$text;
    }
    else {
        return 
false;
    }




כל הזמנים הם GMT +2. הזמן כעת הוא 11:17.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ