PHP-替换动态创建的内容
我在一个文件PHP-替换动态创建的内容,php,Php,我在一个文件jQuery1332199407617=“01”中有很多这样的东西需要删除,但是,这些数字总是不同的,我是否可以通过任何方式删除jQuery和=(数字也总是不同的) 提前谢谢 按要求提供部分文件样本: (如您所见,每次保存时,它都会添加另一个jQuery内容。因此需要删除它) ProjectsTesting I 如果我理解正确,这应该可以: $myContent = preg_replace('/jQuery\d+="(\d+)"/g', 'jQuery="${1}"',
jQuery1332199407617=“01”
中有很多这样的东西需要删除,但是,这些数字总是不同的,我是否可以通过任何方式删除jQuery
和=(数字也总是不同的)
提前谢谢
按要求提供部分文件样本:
(如您所见,每次保存时,它都会添加另一个jQuery内容。因此需要删除它)
ProjectsTesting
-
-
-
-
-
- I
如果我理解正确,这应该可以:
$myContent = preg_replace('/jQuery\d+="(\d+)"/g', 'jQuery="${1}"', $myContent);
请参阅:如果我正确理解您的意思,这应该可以:
$myContent = preg_replace('/jQuery\d+="(\d+)"/g', 'jQuery="${1}"', $myContent);
请参阅:这将删除jQuery文本,无论出现什么数字。它还将删除jQuery标记后留下的标记末尾的多余空间
$old = '<H2 editing="false" revert="Projects:" jQuery1332198888840="12" jQuery1332199361841="12" jQuery1332199407617="12">ProjectsTesting</H2> <UL class=list1 jQuery1332198888840="17" jQuery1332199361841="17" jQuery1332199407617="17"> <LI jQuery1332198888840="16" jQuery1332199361841="16" jQuery1332199407617="16"><A href="#" jQuery1332198888840="15" jQuery1332199361841="15" jQuery1332199407617="15">Praesent vestibulum molestie </A> <LI jQuery1332198888840="19" jQuery1332199361841="19" jQuery1332199407617="19"><A href="#" jQuery1332198888840="18" jQuery1332199361841="18" jQuery1332199407617="18">Aenean nonummy </A> <LI jQuery1332198888840="21" jQuery1332199361841="21" jQuery1332199407617="21"><A href="#" jQuery1332198888840="20" jQuery1332199361841="20" jQuery1332199407617="20">Hendrerit mauris phasellus </A> <LI jQuery1332198888840="23" jQuery1332199361841="23" jQuery1332199407617="23"><A href="#" jQuery1332198888840="22" jQuery1332199361841="22" jQuery1332199407617="22">Porta fusce suscipit varius </A> <LI jQuery1332198888840="25" jQuery1332199361841="25" jQuery1332199407617="25"><A href="#" jQuery1332198888840="24" jQuery1332199361841="24" jQuery1332199407617="24">Cum sociis natoque</A> <LI jQuery1332198888840="27" jQuery1332199361841="27" jQuery1332199407617="27"><A href="#" jQuery1332198888840="26" jQuery1332199361841="26" jQuery1332199407617="26">Penatibus et magnis dis</A>I <LI jQuery1332198888840="29" jQuery1332199361841="29" jQuery1332199407617="29"><A href="#" jQuery1332198888840="28" jQuery1332199361841="28" jQuery1332199407617="28">Parturient montes</A> </LI></UL></DIV>';
//This will erase all the jQuery strings.
$new = preg_replace('/jQuery\d+="\d+"/', '', $old);
//This will take out the extra spaces at the end of the tags that was left open.
$new = preg_replace('/\s+>/', '>', $new);
echo $new;
$old='ProjectsTesting- >
';
//这将删除所有jQuery字符串。
$new=preg_replace('/jQuery\d+=“\d+”/”,''$old);
//这将去掉保留打开的标记末尾的额外空格。
$new=preg_replace('/\s+>/','>',$new);
echo$new;
有关更多信息,请参阅:这将删除jQuery文本,无论出现什么数字。它还将删除jQuery标记后留下的标记末尾的多余空间
$old = '<H2 editing="false" revert="Projects:" jQuery1332198888840="12" jQuery1332199361841="12" jQuery1332199407617="12">ProjectsTesting</H2> <UL class=list1 jQuery1332198888840="17" jQuery1332199361841="17" jQuery1332199407617="17"> <LI jQuery1332198888840="16" jQuery1332199361841="16" jQuery1332199407617="16"><A href="#" jQuery1332198888840="15" jQuery1332199361841="15" jQuery1332199407617="15">Praesent vestibulum molestie </A> <LI jQuery1332198888840="19" jQuery1332199361841="19" jQuery1332199407617="19"><A href="#" jQuery1332198888840="18" jQuery1332199361841="18" jQuery1332199407617="18">Aenean nonummy </A> <LI jQuery1332198888840="21" jQuery1332199361841="21" jQuery1332199407617="21"><A href="#" jQuery1332198888840="20" jQuery1332199361841="20" jQuery1332199407617="20">Hendrerit mauris phasellus </A> <LI jQuery1332198888840="23" jQuery1332199361841="23" jQuery1332199407617="23"><A href="#" jQuery1332198888840="22" jQuery1332199361841="22" jQuery1332199407617="22">Porta fusce suscipit varius </A> <LI jQuery1332198888840="25" jQuery1332199361841="25" jQuery1332199407617="25"><A href="#" jQuery1332198888840="24" jQuery1332199361841="24" jQuery1332199407617="24">Cum sociis natoque</A> <LI jQuery1332198888840="27" jQuery1332199361841="27" jQuery1332199407617="27"><A href="#" jQuery1332198888840="26" jQuery1332199361841="26" jQuery1332199407617="26">Penatibus et magnis dis</A>I <LI jQuery1332198888840="29" jQuery1332199361841="29" jQuery1332199407617="29"><A href="#" jQuery1332198888840="28" jQuery1332199361841="28" jQuery1332199407617="28">Parturient montes</A> </LI></UL></DIV>';
//This will erase all the jQuery strings.
$new = preg_replace('/jQuery\d+="\d+"/', '', $old);
//This will take out the extra spaces at the end of the tags that was left open.
$new = preg_replace('/\s+>/', '>', $new);
echo $new;
$old='ProjectsTesting- >
';
//这将删除所有jQuery字符串。
$new=preg_replace('/jQuery\d+=“\d+”/”,''$old);
//这将去掉保留打开的标记末尾的额外空格。
$new=preg_replace('/\s+>/','>',$new);
echo$new;
有关更多信息,请参阅:我正在考虑preg_match,但idk如何用它重新拼贴:/我在Regexa失败您确定源文档中确实有这些内容吗?不仅在浏览器呈现的DOM中,而且在源文档中也有明确的定义。。(文件来自一个简单保存的div)真的吗?对我来说,它看起来像是某个jQuery IE兼容性插件的输出。在文本编辑器中搜索/替换?我在想preg_match,但idk如何用它重新编程:/我在regexAre失败了。你确定这些东西确实在源文档中吗?不仅在浏览器呈现的DOM中,而且在源文档中也有明确的定义。。(文件来自一个简单保存的div)真的吗?在我看来,它看起来像是某个jQuery IE兼容插件的输出。在文本编辑器中搜索/替换?嗯,我得到以下错误:错误:警告:preg_match()[function.preg match]:分隔符不能是字母数字或反斜杠在正则表达式的开头和结尾添加正斜杠。请确保您使用的是
preg\u replace
,而不是preg\u match
。我收到以下错误:错误:警告:preg\u match()[function.preg match]:分隔符不能是字母数字或反斜杠在正则表达式的开头和结尾添加正斜杠。确保您使用的是preg\u replace
,而不是preg\u match
。您可能在测试时出错。我已经测试了代码,并使用您的示例输入验证了它是否正常工作。所有jQuery标记和额外空格都将从$new中删除。您可能在测试它时出错。我已经测试了代码,并使用您的示例输入验证了它是否正常工作。所有jQuery标记和额外空格都将从$new中删除。