Page 1 of 1
help: eregi_replace()
Posted: Wed Oct 25, 2006 9:46 am
by karenhuang
I have the following cpde to understand, however, I am not quite sure about
$loc = eregi_replace("[[:space:]]+", " ",str_replace(","," ",$info["CITY"])
$info is an String array, with one of keys "CITY".
It do some string replace, and then what?
What's "[[:space:]]" used for??
Posted: Wed Oct 25, 2006 11:23 am
by volka
[:classname:] are predefined sets of characters. [:space:] includes all kind of whitespaces like space, tab, line breaks and so on.
Please use pcre (pcre_replace) instead of posix regular expressions (eregi_replace).
http://de2.php.net/regex wrote:Tip: PHP also supports regular expressions using a Perl-compatible syntax using the
PCRE functions. Those functions support non-greedy matching, assertions, conditional subpatterns, and a number of other features not supported by the POSIX-extended regular expression syntax.
Posted: Thu Oct 26, 2006 8:40 am
by karenhuang
Thanks a lot. That's really clear for me now.
Posted: Thu Oct 26, 2006 8:45 am
by karenhuang
Still have some questions about this??
$loc = eregi_replace("[[:space:]]+", " ",str_replace(","," ",$info["CITY"])
Then why it uses [[: :]] instead of [::] -- "[[:space:]]" , and what's "+" for after "[[:space:]]" ??
Posted: Thu Oct 26, 2006 8:55 am
by volka
[ ] marks a set of characters, like [0-9].
You can use predefined classes within other sets, like [[:space:]a-k]
But here it's just redundant, could be [:space:] as well.
+ means "1 or more occurrences"
* means "0 or more occurrences"
? means "0 or 1 occurrence"
Posted: Fri Oct 27, 2006 1:45 pm
by karenhuang
Now it's really clear now. Thank volka.