Anonymous Anonymous - 2 years ago 223
PHP Question

Finding and replacing all words that ends with 'ing'

I'm trying to find and replace all words that ends with 'ing'. How would I do that?

$text = "dreaming";
if (strlen($text) >= 6) {

if (0 === strpos($text, "ing"))
//replace the last 3 characters of $text <---not sure how to do this either
echo $text;
echo "true";



Want Result:


Answer Source

You could also use substr

$text = "dreaming";

if (substr($text, (strlen($text) - 3), 3) === 'ing') {
  $text = substr($text, 0, (strlen($text) - 3));
echo $text;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download