how do i find a word in the source string and remove the matching words from the target string in php?

you can compare string word count and then explode both and found out diff and then implode it.

<?php

$str_source = "CLOBETASOL PROPIONATE";
$str_target = "CLOBETASOL PROPIONATE 0.05% CREAM TUBE";

if(str_word_count($str_target) >= str_word_count($str_source)){
    echo $finalStringarray = implode(' ',array_diff(explode(' ',$str_target),explode(' ',$str_source)));
}
if(str_word_count($str_source) >= str_word_count($str_target)){
    echo $finalStringarray = implode(' ',array_diff(explode(' ',$str_source),explode(' ',$str_target)));
}

https://3v4l.org/p3o8n

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top