0

I am trying to split a variable that holds an articles content.

I want to loop through it to find keywords but I want to break up the content into an array.

preg_split("/[.,] \s /", $content);

So what I am doing here is splitting the content based on a "." or "," or a white space.

I was reading two different articles here on stack overflow one speaking about the split that is used like explode().

The other was about how the above syntex would work but I added the \s so I am assuming that is where I am going wrong. I have tried the \s within the bracket and out but still can't get it to work.

Shinerrs
  • 129
  • 2
  • 13

1 Answers1

0

If is a split for any of this options that you have mentioned space or . or , the right pattern should be

preg_split("/[ .,]/", $content);
              |_ Note the whitespace here

Your expression is saying that it should have a . or , and a space and any \s (space/enter/tab) and another space

Jorge Campos
  • 22,647
  • 7
  • 56
  • 87