How to Replace Substring in PHP?

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Problem:- How to Replace Substring in PHP? You want to replace a substring with a different string. Example you want to show only 4 digit of a credit card number before printing it.

Solution – Replace Substring in PHP

<?php
$credit_card_no = '1234 5678 9123 9582';
$mask_credit_card_no = substr_replace($credit_card_no, 'xxxx ', 0,strlen($credit_card_no)-4);
print $mask_credit_card_no;
?>

How it Works?

substr_replace($oldstring, $new, $start, $end );

This function replace $old string with $new string and $start variable where you want to start to change and $end where you want to end. about code will print xxxx 9582.

इसे भी पढ़े – MPL Game से पैसे कैसे कमाए?

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *