开发者

preg_replace replace whole string

my preg_replace replaces my whole string instead of just the bit where the expression fits.

Code:

http://beta.yapaste.com/bd

This is what I want replaced:

<t开发者_Python百科able id=\"post24100391\" style=\"width: 100%;\" class=\"p4\" >

Thanks for help.


yes..... that regex matches the entire table.... it will replace the entire string with $replace.

what is it you want to replace?

You could use capturing replacement...

preg_replace("/(<table.*?>).*(<\/table>)/","\$1$replace\$2},$str);

Or you could use a non-capturing group around the parts to not replace...

e.g.

preg_replace("/(?:<table.*?>).*(?:<\/table>)/",$replace,$str) //not tested, though

EDIT in response to OP change

preg_replace("/<table.*?>/",$replace,$str);

You wanted to use lazy capturing *?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜