我有$str= "ns.kimsufi.com ks392904.kimsufi.com ks392904.kimsufi.com"
我想让他们像串一样:
$str= "ns.kimsufi.com
ks392904.kimsufi.com
ks392904.kimsufi.com"
在PHP中执行此类操作的最简单方法是什么?
问题没有解决...... 这是完整的代码:
<?php
$str= 'res Athéna 2 rue Henri Bergson<br/>
<b>Tech City: </b>STRASBOURG<br/>
<b>Tech State/Province:<br/>
</b><b>Tech Postal Code: </b>67200<br/>
<b>Tech Country: </b>FR<br/>
<b>Tech Phone: </b>+33.679795486<br/>
<b>Tech Phone Ext:<br/>
</b><b>Tech Fax:<br/>
</b><b>Tech Fax Ext:<br/>
</b><b>Tech Email: </b><a href="mailto:fnt25qgfilw16kj60goe@h.o-w-o.info">fnt25qgfilw16kj60goe@h.o-w-o.info</a><br/>
<b>Name Server: </b><a href="/index.php?query=213.186.33.199&output=nice">ns.kimsufi.com</a><br/>
<b>Name Server: </b><a href="/index.php?query=176.31.107.145&output=nice">ks392904.kimsufi.com</a><br/>
<b>Name Server: </b><a href="/index.php?query=176.31.107.145&output=nice">ks392904.kimsufi.com</a><br/>
<b>DNSSEC: </b>unsigned<br/>
<b>URL of the ICANN WHOIS Data Problem Reporting System:<br/>
</b><a href="http://wdprs.internic.net" target="_blank">http://wdprs.internic.net</a>/<br/>
>>> Last update of WHOIS database: 2015-06-07T10:20:36.0Z <br />
</td></tr>
</table><br />
<form name="queryform" method="post" action="/index.php">
<table cellpadding="6" cellspacing="0" border="0" width="540" dir="ltr">
<tr><td bgcolor="#92CAFE">
<table width="100%" cellpadding="0" cellspacing="0" border="0" dir="ltr">
<tr class="upperrow">
<td align="left" valign="top" nowrap="nowrap"><font face="Arial" size="+0"><b>Enter any domain name:</b></font></td>
</tr>
<tr class="middlerow">
<td align="center" valign="middle" nowrap="nowrap"><input type="text" name="query" value="" class="queryinput" /> <input type="submit" name="submit" value="Check Domain" /></td>
</tr>
<tr class="lowerrow">
<td align="right" valign="bottom"></td>
</tr>
</table>';
$dom = new DOMDocument;
@$dom->loadHTML($str);
$xp = new DOMXPath($dom);
$links = $xp->query('//b[text()="Name Server: "]/following-sibling::a[1]');
foreach ($links as $link) {
$newlink = $link->nodeValue . PHP_EOL;
$newlink = str_replace(' ', "\n", $newlink);
echo $newlink;
}
?>
它仍然像那样回应:
ns.kimsufi.com ks392904.kimsufi.com ks392904.kimsufi.com
有什么问题? 如果它们之间没有空间那是什么? 有没有机会在不使用str_replace的情况下更改代码?
答案 0 :(得分:0)
只需用换行符替换空格。
preg_replace('~\h~', '\n', $str);
仅仅{p> str_replace
对于这项工作就足够了。但是如果你想要替换选项卡,你必须使用上面的内容。
str_replace(' ', "\n", $str);
答案 1 :(得分:0)