如何在HTML替换一个代码,如何用一个不同的PHP代码替换一长串html代码?

如果replace你的意思是删除所有嵌套< TR>和< TD>在$文本标签并插入$ NEW_TEXT(其中包含嵌套< TD>标签一对夫妇< TR>标签的,但没有标签)在他们的位置;那么使用preg_replace可能会有所斩获。下面的代码片段显示了如何:

IF $ something,$ var1 THROUGH $ var4,$ new_var1 THROUGH $ new_var44 ARE REAL VARIABLES;下面的代码段将采取处理这件事...

$text = "

{$something}
{$var1} {$var2}{$var3}{$var4}
{$something}
";

$new_text = "

{$new_var1} {$new_var2}{$new_var3}{$new_var4}{$new_var11} $new_var22}{$new_var33}{$new_var44}";

// THIS WILL REMOVE EVERYTHING BETWEEN

// IN $text AND REPLACE THEM WITH THE CONTENTS OF $new_text

$result = preg_replace("#(

)(.*)()#si", "$1{$new_text}$3", $text);

IF $的东西,$ VAR1 THROUGH VAR4 $,$ new_var2到$ new_var44是保存没有价值只是字符串;下面的代码片段会照顾的那...

$text = "

\$something
\$var1 \$var2\$var3\$var4
\$something
";

$new_text = "

\$new_var1 \$new_var2\$new_var3\$new_var4\$new_var11 \$new_var22\$new_var33\$new_var44";

// THIS WILL REMOVE EVERYTHING BETWEEN

// IN $text AND REPLACE THEM WITH THE CONTENTS OF $new_text

$result = preg_replace("#(

)(.*)()#si", "$1{$new_text}$3", $text);

echo ($result);

欢呼和好运;-)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值