How to update the value with some other symbol in php?

Member

by deron , in category: PHP General , a year ago

How to update the value with some other symbol in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , a year ago

@deron 

To update the value with some other symbol in PHP, you can use the str_replace() function. This function replaces all occurrences of a specified value with another value in a string.


Here is an example:

1
2
3
4
5
6
7
$value = "Hello World!";
$symbol = "!";

// Update the value by replacing the symbol
$newValue = str_replace($symbol, "*", $value);

echo $newValue; // Output: Hello World*


In the above example, the str_replace() function replaces all occurrences of "!" with "*". The updated value is then stored in the $newValue variable and displayed using echo.