Assigning a New Character in a String in PHP

Q

How To Assigning a New Character in a String?

✍: FYIcenter.com

A

The string element expression, $string{index}, can also be used at the left side of an assignment statement. This allows you to assign a new character to any position in a string. Here is a PHP script example:

<?php 
$string = 'It\'s Friday?';
echo "$string\n";
$string{11} = '!';
echo "$string\n";
?>

This script will print:

It's Friday?
It's Friday!

 

Concatenating Two Strings in PHP

Accessing a Specific Character in String in PHP

Understanding PHP String Literals and Operations

⇑⇑ PHP Tutorials

2016-10-13, 1566🔥, 0💬