php 删除该字符之前的所有内容

标签 php mysql

我有以下 mysql php 数组结果。

while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo '<tr>';
echo "<td> {$row['cust']} </td>".
     "<td> {$row['manu']} </td>".
     "<td> {$row['model']} </td>".
     "<td> {$row['serial']} </td>".
     "<td> {$row['capacity']} </td>".
     "<td> {$row['firmware']} </td>".
     "<td> {$row['deviceid']} </td>".
     "<td> {$row['ataver']} </td>".
     "<td> {$row['ltime']} </td>".
     "<td> {$row['date']} </td>".
     "<td> {$row['ourref']} </td>".
     "<td> {$row['result']} </td>";


/**                     foreach($row as $key=>$value) {
                                echo '<td>',$value,'</td>';
                        }*/
                        echo '</tr>';

"<td> {$row['capacity']} </td>".数组保存如下信息

250000000000 bytes [250 GB]
400000000000 bytes [400 GB]
500000000000 bytes [500 GB]

我想删除所有内容,包括字节。

所以期望的输出看起来像

250 GB
400 GB
500 GB

如何使用上面的代码实现此目的?

提前致谢。

最佳答案

很简单,看这里:

$String = "250000000000 bytes [250 GB]";

$String2 = substr($String, 0, 3); // take the first 3 caracteres

$result = $String2." GB"; // Just add GB after
echo $result;

只需替换 "<td> {$row['capacity']} </td>".与以下

   "<td>".substr($String, 0, 3)." GB</td>".

关于php 删除该字符之前的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318971/

相关文章:

php - MySQL 连接而不是 "nested while loop"

php - 防止对同一脚本的两次调用选择同一 mysql 行

php - 对 wp_query 中的 meta_value 进行排序,但在排序前删除特殊字符

mysql - 使用 Inner Join 在 SQL 中查找已关闭/赢得的机会中入站与出站的百分比

java - 全局 MySQL 连接还是每个请求一个连接?

php - XAMPP 上的 Cron (windows)

php - 如何在 Agile Toolkit 中呈现表单对象(获取 HTML)?

PHP投票强度/力度?

PHP:Guzzle 6 + Guzzle 缓存中间件

php - 通过查询在 PHP 中删除 Access 数据库