How to convert shipping address into html format using magento 2?

In Magento 2 we can convert Shipping address or billing address into Html format using below code snippet. Sometimes we need to display entire shipping address into CSV column or any specific page at that time below html format will be useful.

You are familiar with How to Get Customer Default billing and shipping address   You can also use shipping/billing address from above way.

For Example, We have just get order shipping address, First load order by order id and after getting order id we have fetch order shipping address.
Call below construct in your php file,

<?php
class MassExport {
    public function __construct(
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Customer\Model\Address\Config $addressConfig
    ) {
        $this->orderRepository = $orderRepository;
        $this->_addressConfig = $addressConfig;
    }

    /**
     * Render an address as HTML and return the result
     *
     * @return string
     */
    public function _getAddressHtml($orderId)
    {
        try {
            $order = $this->orderRepository->get($orderId);
        } catch (NoSuchEntityException $e) {
            throw new \Magento\Framework\Exception\LocalizedException(__('This order no longer exists.'));
        }
        $address = $order->getShippingAddress();
        $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
        return $renderer->renderArray($address);
    }
}

You need to get address renderer using \Magento\Customer\Model\Address\Config class.
pass html format code and you will get html formatted address.

Call from template file,

    $orderId = 10;
    $shippingAddress = $this->_getAddressHtml($orderId);
    $shippingFormat = strip_tags($this->_getAddressHtml($shippingAddress));
    echo $shippingFormat;

The result will be,

Veronica Costello
6146 Honey Bluff Parkway
Calder,  Michigan, 49628-7978
United States
T:(555) 229-3326

How to override Customer form/login.phtml file to custom module in magento 2?

We can override form/login.phtml file by just copy login.phtml file to our theme level easily without any code customization. login.phtml file contains the code of login form of site,They contain email and password field.

For custom module requirement, we need to overwrite login.phtml file in module level so we need to create customer_account_login.xml file.
Create XML file at app/code/Rbj/Customer/view/frontend/layout/customer_account_login.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_form_login">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Rbj_Customer::form/login.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Now keep our login.phtml file at app/code/Rbj/Customer/view/frontend/templates/form/login.phtml
Keep content from core login.phtml file to our custom file.
Run command,
php bin/magento cache:clean

Open link, {YOUR_SITE_URL}/customer/account/login
You can get your override file changes.

How to Create customer and add new address programmatically in magento 2?

To create customer and customer addresses programmatically in Magento 2, You need to study the entire article and implement the code in your website.

Given the below code checks, the Customer exists or not using the email id. If the customer is new, Add a new customer and add the given address to the same customer otherwise display an already existing customer message.

<?php
$customerInfo =[
    'customer' =>[
        'firstname'    => 'Rakesh',
        'email'        => 'rakesh.jesadiya@aaaa.com', //customer email id
        'lastname'     => 'jesadiya',
        'password' => 'admin123',
        'prefix' => 'Mr',
        'suffix' => ''
    ],
    'address' =>[
        'firstname'    => 'Rakesh',
        'lastname'     => 'Jesadiya',
        'prefix' => 'Mr',
        'suffix' => '',
        'street' => 'Abcd street',
        'city' => 'Los Angeles',
        'country_id' => 'US',
        'region' => 'California',
        'region_id' => '12', // State region id
        'postcode' => '45454',
        'telephone' => '1234512345',
        'save_in_address_book' => 1
    ]
];

$block->createCustomer($customerInfo);

In the Block file, Pass customer-required data from the above $customerInfo array,

<?php

namespace Rbj\CreateCustomer\Block;

class CustomerAddress extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Api\Data\AddressInterfaceFactory $dataAddressFactory,
        \Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
        array $data = []
    ) {
        $this->storeManager = $storeManager;
        $this->customerFactory = $customerFactory;
        $this->dataAddressFactory = $dataAddressFactory;
        $this->addressRepository = $addressRepository;
        parent::__construct($context, $data);
    }

    /** Create customer
     *  Pass customer data as array
     */
    public function createCustomer($data) {
        $store = $this->storeManager->getStore();
        $storeId = $store->getStoreId();
        $websiteId = $this->storeManager->getStore()->getWebsiteId();
        $customer = $this->customerFactory->create();
        $customer->setWebsiteId($websiteId);
        $customer->loadByEmail($data['customer']['email']);// load customer by email to check if customer is availalbe or not
        if(!$customer->getId()){
            /* create customer */
            $customer->setWebsiteId($websiteId)
                    ->setStore($store)
                    ->setFirstname($data['customer']['firstname'])
                    ->setLastname($data['customer']['lastname'])
                    ->setPrefix($data['customer']['prefix'])
                    ->setMobile($data['customer']['mobile'])
                    ->setEmail($data['customer']['email'])
                    ->setPassword($data['customer']['password']);
            $customer->save();

            /* save address as customer */
            $address = $this->dataAddressFactory->create();
            $address->setFirstname($data['address']['firstname']);
            $address->setLastname($data['address']['lastname']);
            $address->setTelephone($data['address']['telephone']);

            $street[] = $data['address']['street'];//pass street as array
            $address->setStreet($street);

            $address->setCity($data['address']['city']);
            $address->setCountryId($data['address']['country_id']);
            $address->setPostcode($data['address']['postcode']);
            $address->setRegionId($data['address']['region_id']);
            $address->setIsDefaultShipping(1);
            $address->setIsDefaultBilling(1);
            $address->setCustomerId($customer->getId());
            try
            {
                $this->addressRepository->save($address);  
            }
            catch (\Exception $e) {
                return __('Error in shipping/billing address.');
            }
        } else {
            return __('Customer is already exist!');
        }
    }
    
}

Run the indexer command to see a customer in the admin panel,

php bin/magento indexer:reindex
php bin/magento cache:flush