PHP Changing a word from a variable

Asked

Viewed 29 times

0

Personal how can I do with php the following situation:

I have a variable that is coming to the following example information:

$filename = "/wp-content/uploads/1.avi";

as I do to change only this final extension instead of 1.avi I would like it to be 1.mp4

I found this code no longer working follows below

$str = $nome_do_arquivo;
str_ireplace(".avi",".mp4",$str);

1 answer

2


$nome_do_arquivo = "/wp-content/uploads/1.avi";
$str = str_ireplace(".avi", ".mp4", $nome_do_arquivo);

Strings are immutable in PHP. They occupy a certain space in the memory stack, and when you try to modify them, it is possible that their new size will be different, and so it is necessary to allocate this new string in another memory space that can store it.

As a result, whenever you modify a string, a new string is created, and you need to store that new string in a new variable, or reassign the value in the old variable.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.