Thursday 19 May 2022

PHP Regex Sample Code


A regular expression (shortened as regex or regexp or rational expression) is a sequence of characters that specifies a search pattern in the text.

A good testing site is 

https://infoheap.com/php-preg_match-online/ 

Examples of regex for password

PHP Version

/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z])(?=\S*[\W]).{8,}$/


Must have special characters

(?=\S*[\W])


Must have a number

(?=.*\\d)


Must have uppercase and lowercase

(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z])


Some reference

https://stackoverflow.com/questions/8141125/regex-for-password-php

https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a

Share:

Friday 22 April 2022

Tuesday 8 March 2022

Wednesday 9 February 2022

Changing .env Programatically

With great powers comes great responsibility, changing .env values in the server were great but if you don't have access to it this code might come in handy.

In your route, where key is the key, and value will be the new env value


Route::get('changeenv/{key?}/{value?}',"controller@methodname"); 

In your controller


  public function changeEnv($key, $value)
    {
        $path = app()->environmentFilePath();

        $escaped = preg_quote('=' . env($key), '/');

        file_put_contents($path, preg_replace(
            "/^{$key}{$escaped}/m",
            "{$key}={$value}",
            file_get_contents($path)
        ));

        return "env change successfully " .  env($key);
    }

In your browser, you could type this to change the .env's CAPTCHA value

https://mysite.com/changeenv/CAPTCHA/new_value
Share:

Tuesday 8 February 2022

Laravel SMTP Settings for Different Mail Service Provider

Laravel SMTP Settings for Different Mail Service Provider MAILHOG

brew update && brew install mailhog
For Laravel .env

MAIL_DRIVER=smtp
MAIL_HOST=0.0.0.0
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Run in Terminal

mailhog
Testing Email Open this link Mailhog UI

Just continue sending email
Share:

Monday 7 February 2022

Makefile miscellaneous commands

Some miscellaneous commands for makefile This command will cd to a page and run command inside the page, if successful succeeding commands will be called.


build:adminx	font	js

js:
	npm run build

font:
	npm run gulp iconfont

adminx:
	cd admin; npm run build
    
    
Share:

Monday 31 January 2022

Thursday 27 January 2022

PHP Google GeoCoding Getting Latitude & Longitude

  
private function getGeoLocation($address)  
   {  
     try {  
       $url = 'https://maps.google.com/maps/api/geocode/json';  
       $address = str_replace(["'", '"'], " ", $address);  
       $address = str_replace([" ", " "], "+", $address);  
       $query_array = array(  
         'address' => $address,  
         'key' => env('GOOGLE_MAP_API_KEY')  
       );  
       $query = http_build_query($query_array);  
       $content = file_get_contents($url . '?' . $query);  
       $output = json_decode($content);  
       $result = [];  
       if ($output->status == "OK") {  
         $result['latitude'] = $output->results[0]->geometry->location->lat;  
         $result['longitude'] = $output->results[0]->geometry->location->lng;  
       }  
       return $result;  
     } catch (\Exception $ex) {  
       return [];  
     }  
   }  
Share:

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.