我在一个文件jQuery1332199407617="01"
中有很多需要删除的数字,但是,这些数字总是不同的,我可以删除jQuery
和="(number is also always different)"
之间的所有内容吗?
提前谢谢。
要求的部分文件样本:(正如你所看到的,它每次保存时都会添加另一个jQuery。因此需要删除它)
<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>
这将删除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;
有关更多信息,请参阅:http://php.net/manual/en/function.preg-replace.php
如果我理解正确,这应该有效:
$myContent = preg_replace('/jQuery'd+="('d+)"/g', 'jQuery="${1}"', $myContent);
请参阅:http://php.net/manual/en/function.preg-replace.php