PHP 用交替的字符串替换字符串
我有一个类似这样的文本:
$sText =
"www.domain.com
www.domain.com
www.domain.com
www.domain.com
www.domain.com
...";
现在我想将域传播到子域(例如 3 个子域),所以结果应该如下所示:
$aSubs = array("www.sub1.domain.com", "www.sub2.domain.com", "www.sub3.domain.com");
$sResult =
"www.sub1.domain.com
www.sub2.domain.com
www.sub3.domain.com
www.sub1.domain.com
www.sub2.domain.com
..."
感谢帮助...
I have a text something like this:
$sText =
"www.domain.com
www.domain.com
www.domain.com
www.domain.com
www.domain.com
...";
Now I want to spread the domains to subdomains (e.g. 3 sub-domains), so the result should look like this:
$aSubs = array("www.sub1.domain.com", "www.sub2.domain.com", "www.sub3.domain.com");
$sResult =
"www.sub1.domain.com
www.sub2.domain.com
www.sub3.domain.com
www.sub1.domain.com
www.sub2.domain.com
..."
Thanks for help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的替换回调中,执行类似的操作:
我将把正则表达式写给您(因为您没有提供任何详细信息。)
PS:函数中的
static
关键字引用一个变量这是在多个函数调用之间维护的。In your replace callback, do something similar to this:
I'm leaving writing the regex to you (as you didn't give any details.)
PS: The
static
keyword in a function refers to a variable that is maintained between several function calls.如果您有 PHP 5.3:
If you have PHP 5.3:
这可以工作:
This could work: