0

I have the following string

"This is very nice. Thanks for your support."

Now I want to remove the line that contains Thanks word

2
  • 1
    Hi. It is expected that you ask technical questions. Instead you are describing a task, but not what technical problem you have in solving this task. Also see What have you tried?. Commented Jun 27, 2012 at 9:34
  • 2
    $str = str_replace("Thanks","",$str); Commented Jun 27, 2012 at 9:34

3 Answers 3

6

you need to explode the paragraph by fullstop. lets say your full paragraph is store in $str

$lines_arr = explode(".",$str);

now $lines_arr is an array contains numbers of lines.

now under loop you can check which lines contains "thanks" , if it is then skip it.

    $string = '';
    for($i=0; $i<(count($lines_arr)-1); $i++){
     //with the help of strpos
         if(strpos($lines_arr[$i],"Thanks") == false){
             $string .= $lines_arr[$i].". ";
       }
}
Sign up to request clarification or add additional context in comments.

Comments

4

you can use str_replace

echo str_replace("Thanks", "", "This is very nice. Thanks for your support.");
# Output: This is very nice.  for your support.

2 Comments

This would remove the single word, not the sentence that the word appears in.
you are not understanding my problem. I can do this very easily but I dont want the whole sentance that contains the word "Thanks".
1

If you expect proper punctuation, you could explode() the string into an array on the full stops and delete the elements with your particular word, then merge all the elements back into a string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.