How to get the current category name programmatically in Magento 2

Add the following code in your phtml file: How to get the current category name programmatically in Magento 2 How to get the current category name programmatically in Magento 2expound­­­­softtechsolution How to get the current category name programmatically in Magento 2
<?php
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
   echo $catname= $category->getName();

?>