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

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

Matan Levy 29-05-09 10:29

ציטוט:

נכתב במקור על ידי vadimg88 (פרסם 717641)
הנה זה יתמוך ב multibyte וגם הורדתי את ה preg_match והחלפתי בפקודת IF פשוטה.

PHP קוד:

<?php

/**
 * Count number of chars in a string 
 * Supports multi byte chars
 *
 * @param string $string
 */
function countChars$string$encoding='UTF-8' )
{
    return 
mb_strlen($string$encoding);
}

/**
 * Check if the given int is between two values
 *
 * @param int $value
 * @param int $firstElement
 * @param int $secondElement
 * @return bool
 */
function valueInBetween$value$firstElement$secondElement )
{
    return ( (int) 
$value $firstElement && (int) $value $secondElement ) ? TRUE FALSE;
}

# Count english
$string "asfcas";
echo 
countChars($string);

# Count hebrew multi byte
$string "דגעגכדעיגד";
echo 
countChars($string);

# Check if it's bettwen two values, English
$string "asfcas";
var_dump(valueInBetween(countChars($string), 4111)); // true

# Check if it's bettwen two values, Hebrew
$string "שגדעגיעק";
var_dump(valueInBetween(countChars($string), 4111)); // true

$string "שגדעגיעק";
var_dump(valueInBetween(countChars($string), 12111)); // false



עובד לי.
תודה רבה!


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

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