Preg_replace 无法替换我需要的
我需要一些有关 preg_replace 的帮助。在我的网站上,我需要删除一些我不需要的东西。
这是一个例子:
[caption id="attachment_100951" align="alignleft" width="448" caption="THIS IS WHAT I NEED"] [/caption]
好的,我需要从这个字符串中得到的是: caption="THIS TEXT"
中的文本, 我需要删除的所有其他内容,我已经使用过谷歌并尝试了一些示例,但没有任何结果。 也许我需要使用另一个函数,但从我在互联网上读到的内容来看,这应该取代 .
请帮助我,这非常重要。
谢谢。
编辑:
代码还有一些我忘记的事情。
[caption id="attachment_100951" align="alignleft" width="448" caption="eaaaaaaaaaaaaaaaaaa"]
<a href="http://localhost/111baneease1.jpg">
<img class="size-full wp-image-100951" title="zjarr_banese1" src="http://localhost/111baneease1.jpg" alt="eeeeeeeeeeeeeeeee" width="448" height="308" />
</a>
[/caption]
所以我需要获取 CAPTION 文本 并删除其中的所有内容 [caption id="attachment_100951"align="alignleft"width="448"caption="eaaaaaaaaaaaaaaaaaa"]
但
<a href="http://localhost/111baneease1.jpg">
<img class="size-full wp-image-100951" title="zjarr_banese1" src="http://localhost/111baneease1.jpg" alt="eeeeeeeeeeeeeeeee" width="448" height="308" />
</a>
也不想删除[/caption]
。
I need some help with preg_replace. At my website I need to delete some things I don't need.
Here is an example:
[caption id="attachment_100951" align="alignleft" width="448" caption="THIS IS WHAT I NEED"] [/caption]
Ok, all I need from this string is: the text inside caption="THIS TEXT"
,
every thing else I need to be deleted, I have used Google and tried some examples but nothing.
Maybe I need to use another function, but from what I have read on the internet this should replace .
Please help me, it's very important.
Thank you.
EDIT:
The code has some other things that i have forgot.
[caption id="attachment_100951" align="alignleft" width="448" caption="eaaaaaaaaaaaaaaaaaa"]
<a href="http://localhost/111baneease1.jpg">
<img class="size-full wp-image-100951" title="zjarr_banese1" src="http://localhost/111baneease1.jpg" alt="eeeeeeeeeeeeeeeee" width="448" height="308" />
</a>
[/caption]
So i need to get the CAPTION text and delete every thing in
[caption id="attachment_100951" align="alignleft" width="448" caption="eaaaaaaaaaaaaaaaaaa"]
but not
<a href="http://localhost/111baneease1.jpg">
<img class="size-full wp-image-100951" title="zjarr_banese1" src="http://localhost/111baneease1.jpg" alt="eeeeeeeeeeeeeeeee" width="448" height="308" />
</a>
also want delete [/caption]
too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此正则表达式:
将输出:
当应用于:
根据您更新的问题更新答案:
上面的正则表达式应用于:
将输出:
我不确定这是否正是您想要的。当然,您可以使用正则表达式对组 $2 和 $3 进行匹配并执行任何您想要的操作...
This regex :
will output :
when applied to :
Updated answer based on your updated question :
The above regex applied to :
Will output :
I am not sure if this is exactly what you wanted. Of course you can use the regex to match and do whatever you want with groups $2 and $3...