-1

可能重复:
如何在 PHP 中将 ereg 表达式转换为 preg?

我从以下位置收到上述(主题)错误:

if (ereg('<coordinates>([0-9.-]{1,}),([0-9.-]{1,}).*</coordinates>', $result, $regs))

所以我这样做了:

if (preg_match('<coordinates>/[0-9.-]{1,}\/,\/[0-9.-]{1,}/.*</coordinates>/', $result, $regs))

现在谷歌地图根本不显示,它还警告“..找不到坐标......”

我哪里做错了?

谢谢!

4

1 回答 1

0

You need delimiters around your pattern when using PCRE functions:

if (preg_match('~<coordinates>/[0-9.-]{1,}\/,\/[0-9.-]{1,}/.*</coordinates>/~', $result, $regs))

Notice the ~ at the beginning and end.
Normally, people use / as a delimiter, but because it shows up so frequently in your pattern, an alternate delimiter has been selected.

As @nickb mentioned, have a look at this discussion:
How can I convert ereg expressions to preg in PHP?

于 2013-01-21T22:16:33.163 回答