gpt4 book ai didi

PHP:如何以给定格式转换这句话

转载 作者:可可西里 更新时间:2023-10-31 22:58:35 25 4
gpt4 key购买 nike

"[5|five] [Tips|Suggestions] for an Unforgettable Trip|Five suggestions for a un-regret able Trip|[5|five] [tips|suggestions] for an [amazing|incredible] Trip|Five [tips|suggestions] for an astonishing Trip"

"[5|five] [Tips|Suggestions] for an Unforgettable Trip~Five suggestions for a un-regret able Trip~[5|five] [tips|suggestions] for an [amazing|incredible] Trip~Five [tips|suggestions] for an astonishing Trip"

我可以使用 str_replace("|", "~", $code) 但问题是我不想将 "|" 转换为 "~" 如果它在 "[ ]" 之间。

最佳答案

for($i=0,$s=strlen($str),$c=0;$i<$s;++$i){
if($str[$i]=='[')++$c;
elseif($str[$i]==']')--$c;
elseif(!$c && $str[$i]=='|')$str[$i]='~';
}

关于PHP:如何以给定格式转换这句话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6677838/

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