使用 str_replace() 并返回两个不同的版本
我有一个文本区域,可以在其中输入多个域名来检查可用性。 在下面的脚本中,我用“-”替换空格。但我还想要一个不带“-”的域名版本。
举例来说,我输入:
一个好词
god-word
然后我希望脚本返回两者:
a-good-word
a-nother-
a-nother-god-word 还有:
agoodword
anothergodword
$domaininput = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
$change_space = str_replace(" ","-",$domaininput);
$change_new_line = str_replace("\n",",",$change_space);
$manydomains = explode("," , $change_new_line);
foreach ($manydomains as $domain){
//some code
}
如何在 PHP 中做到这一点?
I have a textarea where I can type in multiple domain names to check availability.
In my script below I replace space with “-“. But I also want a version of the domain name without “-”.
Say for example that I type in:
a good word
a nother god word
Then I want the script to return both:
a-good-word
a-nother-god-word
And also:
agoodword
anothergodword
$domaininput = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
$change_space = str_replace(" ","-",$domaininput);
$change_new_line = str_replace("\n",",",$change_space);
$manydomains = explode("," , $change_new_line);
foreach ($manydomains as $domain){
//some code
}
How can that be done in PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
Try:
如果你还没有让它工作,这里有一个粗略的函数来完成这项工作,而且它只会返回唯一的域
if you not got it to work yet here a crude function todo the job plus it will only return unique domains