How can substr_replace() be used effectively in PHP for string manipulation?
substr_replace() can be used effectively in PHP for string manipulation by replacing a portion of a string with another substring. This function allows you to specify the start position, length of the portion to be replaced, and the replacement string. This can be useful for tasks like masking sensitive information, modifying specific parts of a string, or performing complex text transformations.
// Example of using substr_replace() to mask sensitive information
$string = "1234-5678-9012-3456";
$maskedString = substr_replace($string, "****", 0, 12);
echo $maskedString; // Output: ****-3456
Related Questions
- Should PHP, HTML, and CSS be kept separate, or is it acceptable to store the entire HTML code in PHP variables?
- What are the advantages and disadvantages of using popular PHP frameworks like Zend, Symfony, CakePHP, Kohana, Yii, and Codeigniter in real-world applications?
- What are some potential issues with using MySQL queries in PHP, as shown in the provided code snippet?