R K R K - 4 years ago 121
PHP Question

The trim() function is not working in php

I have a string and I want to remove the 'is' word from the string, for that I am using a trim function. But I am not getting the desired result.

Here is my code.

$string1 = "Life is chess.";
$string3 = trim($string1,"is");
echo $string3;

I am getting the output as
Life is chess.

Please comment below for any query.

Answer Source

trim() function removes white space or other chars from the beginning or from the end of the string. If you need to remove chars from the middle of the string, you'll need to use something else. For example, you can use str_replace:

str_replace('is', '', 'this is string');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download