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
| $mp3 = "02. artiste - titre";
$asked_mask = "%6. %1 - %2";
$str = eregi_replace(".mp3$", "", $mp3);
$mask = $asked_mask;
$details = array ('artiste' => "", 'title' => "", 'album' => "");
// on drop les caractères de la fin
if (!eregi("%[0-9]{1}$", $mask)) {
if (($index_mask_last_tag = strrpos($mask, '%')) !== false) {
$drop = substr($mask, $index_mask_last_tag + 2);
$mask = eregi_replace($drop."$", "", $mask);
$str = eregi_replace($drop."$", "", $str);
//print("drop = $drop<br />");
} else {
$mask = "";
}
}
while (strlen ($mask) > 0) {
// on drop les caractères du début
if (!eregi("^%", $mask)) {
if (($index_mask_first_tag = strpos($mask, '%')) !== false) {
$drop = substr($mask, 0, $index_mask_first_tag);
$mask = eregi_replace("^$drop", "", $mask);
$str = eregi_replace("^$drop", "", $str);
}
}
// on cherche le prochain drop (ou balise)
$index_mask_first_tag = 0;
$first_tag = substr($mask, $index_mask_first_tag, 2);
// $index_mask_drop_begin = $index_mask_first_tag + 2;
if (($index_mask_second_tag = strpos($mask, '%', $index_mask_first_tag + 1)) === false) {
$mask = "";
$first_value = $str;
} else {
$first_drop = substr($mask, $index_mask_first_tag + 2, $index_mask_second_tag - ($index_mask_first_tag + 2));
$index_str_first_value = 0;
if (($index_str_first_drop = strpos($str, $first_drop)) === false) {
$first_value = $str;
$mask = "";
} else {
$first_value = substr($str, $index_str_first_value, $index_str_first_drop);
$mask = substr($mask, $index_mask_second_tag);
$str = substr($str, $index_str_first_drop + strlen($first_drop));
}
}
switch ($first_tag) {
case '%1':
$details['artiste'] = $first_value;
break;
case '%2':
$details['title'] = $first_value;
break;
case '%3':
$details['album'] = $first_value;
break;
default:
// pas de besoin
break;
}
}
print ("mp3 = $mp3<br />masque = $mask<br />values = ");print_r($details); |
Partager