我使用PHP从Oracle dB中提取字段。该字段存储firstname:surname
之类的值。如何从字段:
爆炸,以便值保持在html表中的同一行?
<?php
include_once 'dB/oraConfig.php';
$stid = oci_parse($conn, 'SELECT Name FROM Orders');
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
答案 0 :(得分:1)
如果您只想回复&#34;名字姓氏&#34;,以空格分隔,您可以
echo str_replace(":", " ", $item);
用空格重新粉碎所有冒号。
答案 1 :(得分:0)
如果$str
的字符串格式为firstname:surname:
$str="firstname:surname";
$arr=explode(":",$str);
echo $arr[0]." ".$arr[1];
// firstname surname
答案 2 :(得分:0)
尝试将此应用于您的代码
//the variable you want to fix is in tmp
$tmp = "firstname:surname";
//the field gets the result without ':'
$field = explode(':' , $tmp)[0]." ".explode(':', $tmp)[1] ;