gpt4 book ai didi

PHP : How to remove string between "[" and "]"

转载 作者:行者123 更新时间:2023-12-04 15:32:53 25 4
gpt4 key购买 nike

我需要删除 [...] 中的字符串,包括“[]”本身。我尝试从该站点搜索解决方案。我有一个线索,我应该用 preg_replace 尝试一些东西,但对我来说它似乎太专业了。

例如:

[gallery ids="92,93,94,95,96,97,98,99,100" orderby="rand"] Description The thirty-two storey resort condominium in Phuket, located Just 150m from Patong beach where choices of activities, water sp 

我需要从示例文本中删除 [gallery ids="92,93,94,95,96,97,98,99,100"orderby="rand"]。它始终以 [gallery ids=" .

开头。

请提出建议。

最佳答案

试试这个:

$string = '[gallery ids="92,93,94,95,96,97,98,99,100" orderby="rand"] Description The thirty-two storey resort condominium in Phuket, located Just 150m from Patong beach where choices of activities, water sp ';
$string = preg_replace('/\[gallery ids=[^\]]+\]/', '', $string);

分割:

\[gallery ids= 查找以 [gallery ids=

开头的子字符串

[^\]]+\] 匹配 1 个或多个不是 ] 的字符,直到到达 ]

然后将整个匹配的部分替换为 '' 什么都没有,你就有了新的字符串。

关于PHP : How to remove string between "[" and "]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15187486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com