# PHP

# composer 1 memory limit

\## issue  
composer will run into memory limit due to memory leak when checking lot of package.

\## solution:

\### temporary usage unlimited memory

php -d memory\\\_limit=-1 /usr/local/bin/composer require prettus/l5-repository

/usr/bin/composer

php -d memory\\\_limit=-1 /usr/bin/composer update

\### update to composer 2

need to check if current package support composer 2 or not.

# install in centos

\# Centos 8 Stream

``sudo dnf upgrade --refresh -y``

EPEL

``sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm``

REMI

``sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm``

\## if old php is installed

``sudo dnf remove php php-fpm -y``

remove package

``sudo dnf remove php\* -y``

reset list

``sudo dnf module list reset php -y``

\## enable php8.1

show list

``sudo dnf module list php``

enable remi php8.1

``sudo dnf module enable php:remi-8.1``

basic php for laravel

``dnf install php php-fpm php-opcache php-gd php-curl php-mysqlnd php-mbstring php-dom zip unzip php-zip php-json php-pdo php-pdo\_mysql``

other if needed

``php-cli php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml``

confirm installation

``php -v``

# Laragon to Open 2 Different System with different PHP version

Terminal Project with PHP7.4  
```  
cmd.exe /k "set PATH=C:\\laragon\\bin\\php\\php-7.4.33-nts-Win32-vc15-x64;%PATH%"  
```  
Terminal Project with PHP8.3  
```  
cmd.exe /k "set PATH=C:\\laragon\\bin\\php\\php-8.3.7-nts-Win32-vs16-x64;%PATH%"  
```

After run that command, you can use command "php artisan yourcommand" or "composer" like always.

\-- command "composer install"

\*\*Attention : Please rename path based on your php version.. \*\*

# preg_replace

```php  
preg\_replace('//\\W|\_/', '', '') // remove non-alphanumeric

preg\_replace("/\[^A-Za-z0-9 \]/",

preg\_replace('/\[^\\d\]/i', '', '') // remove non-numeric

preg\_replace('/\[^A-Za-z0-9\\ \\/\\-\\n\\,\]+/', '', $address); // remove non alpha + new line, space, some special char   
```