Good news! PHP 7.1 is being actively supported through 20 Sep 2024. After that point, it's advisable to upgrade to the latest version, since the PHP team will only offer security-related support until 20 Sep 2024, at which point PHP 7.1 will be considered "end-of-life".
sudo apt update
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.1
sudo apt install php7.1-common php7.1-mysql php7.1-xml php7.1-xmlrpc php7.1-curl php7.1-gd php7.1-imagick php7.1-cli php7.1-dev php7.1-imap php7.1-mbstring php7.1-opcache php7.1-soap php7.1-zip php7.1-intl -y
php -v
php -i
php -m