Hello, I have a string such as this:
jdgfsaj:234:234:234:234:234
and i want to separate in variables by ':'
I used ereg("(.)🙁.)🙁.)🙁.)🙁.*)", $lines[$j], $regs);
but it don't works, could anyone help me?
Thanks
split?
Why don't you use explode? Syntax like this: $array_of_strings=explode(':', 'jdgfsaj:234:234:234:234:234');
Now you have: $array_of_strings[0]='jdgfsaj', $array_of_strings[0]='234'...etc. You can do anything you want with these values.
I definitely agree with the previous suggestions to use explode() if it's really as simple as your example. However, just to answer your question, the reason it's not working is that the closure operator '*' is "greedy"--i.e. it matches the longest possible sequence of characters, not the shortest one. The key to making this work, then, is to exclude the ':' from the possible match characters:
ereg("([:])🙁[:]) etc...
Or just add the U (Ungreedy) option. Nice and easier, but probably a bit lazy
That's only for PCRE, isn't it?
yes, afaik greediness is only for pcre