I’m having some trouble using str_replace within an if statement. I’m wanting to remove plural formatting (‘s) from some text I’m outputting.
I supply a keyword that is included with the text output. So if my keyword has an ‘s’ as the last character I want the plural characters stripped from the output. For example if the keyword is ‘handbags’ I’m wanting to echo “I love handbags” rather than “I love handbags’s”. This is what I’ve come up with but it does not work.
<?php
$keyword = "handbags";
$string = "I love $keyword's.";
$last = substr($keyword, -1);
if ($last == "s") {str_replace("'s", "", $string);}
echo $string;
?>
if ($last == "s") { $string = str_replace("'s", "", $string);}