将阿拉伯语的日期和时间转换为英语为php 5.2

时间:2016-12-08 09:21:57

标签: php

有意将阿拉伯语的日期和时间转换为英语吗?对于PHP 5.2

我尝试了字符串替换函数和setlocale(),但没有结果。

先谢谢..

1 个答案:

答案 0 :(得分:4)

反过来使用以下代码,您将找到答案

<?php

    // PHP Arabic Date

    error_reporting(E_ALL ^ E_NOTICE);

    $months = array(
        "Jan" => "يناير",
        "Feb" => "فبراير",
        "Mar" => "مارس",
        "Apr" => "أبريل",
        "May" => "مايو",
        "Jun" => "يونيو",
        "Jul" => "يوليو",
        "Aug" => "أغسطس",
        "Sep" => "سبتمبر",
        "Oct" => "أكتوبر",
        "Nov" => "نوفمبر",
        "Dec" => "ديسمبر"
    );

    $your_date = date('y-m-d'); // The Current Date

    $en_month = date("M", strtotime($your_date));

    foreach ($months as $en => $ar) {
        if ($en == $en_month) {
            $ar_month = $ar;
        }
    }

    $find = array (

        "Sat",
        "Sun",
        "Mon",
        "Tue",
        "Wed" ,
        "Thu",
        "Fri"

    );

    $replace = array (

        "السبت",
        "الأحد",
        "الإثنين",
        "الثلاثاء",
        "الأربعاء",
        "الخميس",
        "الجمعة"

    );

    $ar_day_format = date('D'); // The Current Day

    $ar_day = str_replace($find, $replace, $ar_day_format);


    header('Content-Type: text/html; charset=utf-8');
    $standard = array("0","1","2","3","4","5","6","7","8","9");
    $eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
    $current_date = $ar_day.' '.date('d').' / '.$ar_month.' / '.date('Y');
    $arabic_date = str_replace($standard , $eastern_arabic_symbols , $current_date);

    // Echo Out the Date
    echo $arabic_date;

    ?>

OR 你可以用这个

$standard = array("0","1","2","3","4","5","6","7","8","9");
$eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
$current_date = date('d').'-'.date('m').'-'.date('Y');
$arabic_date = str_replace($standard , $eastern_arabic_symbols , $current_date);