Asked  7 Months ago    Answers:  5   Viewed   33 times

I'm trying to build a PHP site and I'm wanting to test my PHP files without uploading them to my host. Basically testing them on my own machine before I upload them. How do I do that?

 Answers

74

Install and run XAMPP: http://www.apachefriends.org/en/xampp.html

Wednesday, March 31, 2021
 
insomiac
answered 7 Months ago
68

From the reference, some month formatting codes:

Symbol     Meaning             Example:            

M          month in year       M or MM    09       
                               MMM        Sept     
                               MMMM       September
                               MMMMM      S        

The PHP function to set the format is: IntlDateFormatter::setPattern, some examples:

class LocaleDateFormat
{
    private $locale;
    private $pattern;

    public function __construct($pattern, $locale = 'en_US') {
        $this->setLocale($locale);
        $this->setPattern($pattern);
    }

    public function setLocale($locale) {
        $this->locale = $locale;
    }

    public function setPattern($pattern) {
        $this->pattern = $pattern;
    }

    public function localeFormat($locale, $date) {
        $this->setLocale($locale);
        return $this->format($date);
    }

    public function format($date) {
        $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL);
        $formatter->setPattern($this->pattern);
        return $formatter->format($date);
    }
}

$dateFormat = new LocaleDateFormat('MMMM'); # Long Month Names

$date = new DateTime(); # Now

$locales = ["en_US", "de_DE", "sv_SE", "ru_RU"];
foreach ($locales as $i => $locale) {
    $month = $dateFormat->localeFormat($locale, $date);
    printf("%d. %s - %sn", $i+1, $locale, $month);
}

Output:

1. en_US - December
2. de_DE - Dezember
3. sv_SE - december
4. ru_RU - ???????

For a list of locales see here:

  • List of available collators in PHP?

The actual example for the short monthnames across different locales:

$locales    = ["en_US", "de_DE", "sv_SE", "ru_RU", 'it', 'it_IT', 'it_CH'];
$dateFormat = new LocaleDateFormat('MMM'); # Short Month Names

$date = new DateTime(); # Now

foreach (range(1, 12) as $monthNumber)
{
    $date->setDate(2012, $monthNumber, 1);

    printf("%02d:    ", $monthNumber);

    foreach ($locales as $locale)
    {
        $monthLabel = $dateFormat->localeFormat($locale, $date);
        $pad = str_repeat(' ', max(0, 8 - mb_strlen($monthLabel, 'UTF-8')));
        printf("%s: %s%s  ", $locale, $monthLabel, $pad);
    }

    echo "n";
}

Exemplary output:

01:    en_US: Jan       de_DE: Jan       sv_SE: jan       ru_RU: ???.      it: gen       it_IT: gen       it_CH: gen       
02:    en_US: Feb       de_DE: Feb       sv_SE: feb       ru_RU: ????.     it: feb       it_IT: feb       it_CH: feb       
03:    en_US: Mar       de_DE: Mär       sv_SE: mar       ru_RU: ?????     it: mar       it_IT: mar       it_CH: mar       
04:    en_US: Apr       de_DE: Apr       sv_SE: apr       ru_RU: ???.      it: apr       it_IT: apr       it_CH: apr       
05:    en_US: May       de_DE: Mai       sv_SE: maj       ru_RU: ???       it: mag       it_IT: mag       it_CH: mag       
06:    en_US: Jun       de_DE: Jun       sv_SE: jun       ru_RU: ????      it: giu       it_IT: giu       it_CH: giu       
07:    en_US: Jul       de_DE: Jul       sv_SE: jul       ru_RU: ????      it: lug       it_IT: lug       it_CH: lug       
08:    en_US: Aug       de_DE: Aug       sv_SE: aug       ru_RU: ???.      it: ago       it_IT: ago       it_CH: ago       
09:    en_US: Sep       de_DE: Sep       sv_SE: sep       ru_RU: ????.     it: set       it_IT: set       it_CH: set       
10:    en_US: Oct       de_DE: Okt       sv_SE: okt       ru_RU: ???.      it: ott       it_IT: ott       it_CH: ott       
11:    en_US: Nov       de_DE: Nov       sv_SE: nov       ru_RU: ????.     it: nov       it_IT: nov       it_CH: nov       
12:    en_US: Dec       de_DE: Dez       sv_SE: dec       ru_RU: ???.      it: dic       it_IT: dic       it_CH: dic      
Wednesday, March 31, 2021
 
axiomer
answered 7 Months ago
66

Problem appears to be specific to PhpStorm as issue can be reproduced on another machine running windows 10

Fix

When placing test.php and test2.php into my XAMPP 7.1 localhost directory, the issue does not appear, this also resolves the issue when placing files into WAMP directory on windows 10

Wednesday, March 31, 2021
 
Valdas
answered 7 Months ago
82

what happens if you

 telnet 10.1.150.109 5672
Saturday, May 29, 2021
 
adjco
answered 5 Months ago
52

If you want to set the locale permanently for that session, change the route code to:

Route::get('/{locale}', function ($locale) {
    App::setLocale($locale);
    Session::put('locale', $locale);
    return view('index');
});

Then add a middleware to check if session has locale, and if so set the locale like so:

public function handle($request, Closure $next) {
    if(Session::has('locale')) {
        app()->setLocale(Session::get('locale'));
    }
    return $next($request);
}
Saturday, May 29, 2021
 
SJain
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :