Remove words from string contained in array

HackerManiac

I have an array $c=array("ok","and","or") and a $str="i am ok and fine" now i want to strip $str from $c array elements so that $str="i am fine" how can i do this?

O. Jones

There are two things going on here. One is the editing of the string to remove the words you've mentioned. The other is the manipulation of the string to handle it word by word. If you just do character replacement you get extra spaces.

So try something like this. Not debugged.

$q = explode(' ',$str);    /* turn string into list of words */
$r = array();
foreach ($q as $w) {       /* check the words */
  if (!in_array($w,$c)) {
    $r[] = $w;
  }
}
$str = implode(' ',$r);   /* turn new list of words back into string */

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

remove repeated words from String Array

From Dev

Remove excess junk words from string or array of strings

From Dev

Remove words from a string in PHP

From Dev

Remove certain words from string

From Dev

How to delete words contained in List<string> deleteCodeList from textile

From Dev

finding words from an array, in a string

From Dev

Extracting words from a string into an array

From Dev

remove all words that start with "@" from a string

From Dev

Remove short words and characters from a string Java

From Dev

remove duplicate words from string in C#

From Dev

Python -Remove capitalized words from long string

From Dev

python, remove words in a string from a list

From Dev

Better way to remove multiple words from a string?

From Dev

How to get words starting with # and remove from string

From Dev

Python: Remove words from a given string

From Dev

Remove lowercase words from python unicode string

From Dev

Remove specific words or letters from a String

From Dev

How to get words starting with # and remove from string

From Dev

Python -Remove capitalized words from long string

From Dev

Remove unique multiple words from string

From Dev

java : remove words from ArrayList<String>

From Dev

Python remove words in every string from list

From Dev

Remove words from a string of variable length

From Dev

If String Is Contained By Brackets, Remove Them

From Dev

Java print out words from a string into an array

From Dev

Split words from string into array but not if they are inbetween slashes

From Dev

Create array with reversed words from user string

From Dev

Split words from string into array but not if they are inbetween slashes

From Dev

Python, find words from array in string

Related Related

  1. 1

    remove repeated words from String Array

  2. 2

    Remove excess junk words from string or array of strings

  3. 3

    Remove words from a string in PHP

  4. 4

    Remove certain words from string

  5. 5

    How to delete words contained in List<string> deleteCodeList from textile

  6. 6

    finding words from an array, in a string

  7. 7

    Extracting words from a string into an array

  8. 8

    remove all words that start with "@" from a string

  9. 9

    Remove short words and characters from a string Java

  10. 10

    remove duplicate words from string in C#

  11. 11

    Python -Remove capitalized words from long string

  12. 12

    python, remove words in a string from a list

  13. 13

    Better way to remove multiple words from a string?

  14. 14

    How to get words starting with # and remove from string

  15. 15

    Python: Remove words from a given string

  16. 16

    Remove lowercase words from python unicode string

  17. 17

    Remove specific words or letters from a String

  18. 18

    How to get words starting with # and remove from string

  19. 19

    Python -Remove capitalized words from long string

  20. 20

    Remove unique multiple words from string

  21. 21

    java : remove words from ArrayList<String>

  22. 22

    Python remove words in every string from list

  23. 23

    Remove words from a string of variable length

  24. 24

    If String Is Contained By Brackets, Remove Them

  25. 25

    Java print out words from a string into an array

  26. 26

    Split words from string into array but not if they are inbetween slashes

  27. 27

    Create array with reversed words from user string

  28. 28

    Split words from string into array but not if they are inbetween slashes

  29. 29

    Python, find words from array in string

HotTag

Archive