Jump to content

[SOLVED] Preg_split - Filtering the "." from strings


transparencia

Recommended Posts

It's not working because I didn't explain myself right, I'm sorry. :-[

 

I want to split strings and use multiple delimiters, not just the . (period) I want to filter:

. - _ ,? ! and white space (" ").

 

I was using

$terms = preg_split("/[\s,]+/", $kernel->vars['string']);

 

But it didn't filter the "." and I don't understand the delimiters character meaning.

 

What are the right delimiters for filtering the above characters?

From what I know, and I could be wrong, the regex for those characters would be:

 

"/[\s][\.][\-][\_][\,][\?][\!]/"

 

There may be an easier way to do this and like I said, it could be wrong. Only one way to find out.....

 

Hope that helps.

You should be able to group those into one character set:

 

"/[\s\.-_,?!]/"

 

Be carefule with the location of the - character in your character class... if it is not the first or last character, this character now signifies a range (instead of a dash). Best to relocate that character..also, you do not need to escape the dot in this case, as it is automatically recognized as a dot (and not a wildcard) character when placed within a character class:

 

"/[\s.,_?!-]/"

 

EDIT - To the OP.. \s is a shorthand character class that encompasses numerous spaces, from individual ones to tabs and returncarriages by example..if you ONLY want an actual space, you can replace \s with a single literal space, or use \x20

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.