我在一个文件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>
发布于 2012-03-20 07:39:52
这将删除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
发布于 2012-03-20 07:37:42
如果我没理解错的话,这应该是可行的:
$myContent = preg_replace('/jQuery\d+="(\d+)"/g', 'jQuery="${1}"', $myContent);请参阅:http://php.net/manual/en/function.preg-replace.php
https://stackoverflow.com/questions/9779457
复制相似问题