开发者

What do these do in php regex?

I found:

1 - $milk = preg_replace( "/(\(\s*)(.+?)(\s*\))/","",$milk);
2 - $milk = ereg_replace( "[^[:space:]A-Za-z0-9&_-]", "", $milk);

$milk is a large 开发者_StackOverflow社区string about a paragraph say.

What do 1 and 2 do to $milk?

Also, ereg has been deprecated acording to php manual. Can this be replaced with some other php in the above code?


The 1 and 2 are part of expressions that evaporate, they do nothing valueable in this context.
It amounts to:

1 - $milk = ("text");

The variable gets set to whatever the function returned. Then PHP will attempt another arithmetic operation, but throw the result away. It's basically 1 - 0; on a line by itself, because the text string gets treated as zero.

Btw, preg_replace is already the newer alternative to ereg_replace. So only the second line needed to be adapted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜