How to change "It's" to "It is" (without apostrophe) using str_replace?

404 views Asked by At

I want to replace from Facebook's relationships string "It's complicated" to other text.

The line is like this:

$user->relationship = str_replace(array('single', 'It's complicated'), array('Soltero(a)', 'Es complicado'),$data['relationship_status']);

Using: 'It's complicated' , 'It's complicated' or 'It's complicated' , do not work.

Any suggestions?

Thanks a lot.

Regards.

1

There are 1 answers

3
azisfatoni On BEST ANSWER

If you want to use literal single quoted character ('), you have to escape them.

like:

$str = '\''; // single quote

You could try this.

$user->relationship = str_replace(array('single', 'It\'s complicated'), array('Soltero(a)', 'Es complicado'),$data['relationship_status']);

The PHP could not recognize the single literal quoted character (') without escape sequences character. Here is the explanation about it: Strings literal

It's also happen for double literal quoted character (").