doubi4340 2015-06-16 02:26
浏览 34
已采纳

修剪功能不起作用

Hi (sorry for my english xD),

I'm taking data of my DB in MySql, this data (pair of players in format 'Player 1 - Player 2'). I cut this with explode function by character - therefore I get 'Player 1 ' and ' Player 2' string. I try delete white spaces at the beginning and the end with trim function, but this don't work. I suspect that this trouble is similar to other with the - character, the normal - of my keyboard don't split the string with explode function, I had to go to PHPMyAdmin and copy the - character of the one existing string and paste this in the second explode function parameter, after this, explode function work.

I try the same of the - character (Login in PHPMyAdmin copy one whitespace and paste this as second parameter of trim function but this time don't work :( ).

Also try with str_replace function (no matter what the gaps are eliminated) and don't work, also try with preg_replace function etc... nothing has work because apparently the white space saved in DB isn't the same of my keyboard, I suspect that the problem is related with charset's or collations but I don't have idea what I should do, because the table, link, charset of PHP and other thing are in UTF-8 and utf8-spanish-ci collation and charset.

Aclaration: The input of the data is made by xdom (PHP) from other site not controlled for me.

<tbody>
<?php while ($partidos = mysqli_fetch_array($sql)) { ?>
    <tr>
        <td class="center"><?php echo $partidos['fecha']; ?></td>
        <td><?php $participante = explode("₋", $partidos['jugadores']);
            $participante1 = trim($participante[0]);
            $participante2 = trim($participante[1]);

            echo trim($participante1) . "<br>vs<br>" . trim($participante2);
            ?></td>
        <td><?php if ($partidos['estado'] == 0) { ?> En Curso<?php } elseif ($partidos['estado'] == 1) {
                if ($partidos['alerta'] == 0) { ?> Terminado<?php } else { ?>Terminado - Error <i
                    class="fa fa-exclamation-triangle"></i><?php }
            } ?></td>
        <td><?php if ($partidos['alerta_medica'] == 1) { ?> Si <i class="fa fa-2 fa-medkit"
                                                                  style="color:#C00;"></i><?php } else { ?> No<?php } ?>
        </td>
        <?php if ($_SESSION['tipo'] == 1 || $_SESSION['tipo'] == 2) { ?>
            <td class="center">
            </td>
        <?php } ?>
    </tr>
<?php } ?>
</tbody>

Screenshot from command line

  • 写回答

2条回答 默认 最新

  • douwo5710 2015-07-05 22:08
    关注

    I found the problem thanks to @Rick James, watching the hexadecimal response of the database i noticed that two spaces are x20, but one is xC2 xA0. Reading in other post of stackoverflow, i found that xC2 xA0 is a Non-break space, but this is not recognized for the trim function. The solution was specify this as second parameter of the function:

    $participante1 = trim($participante[0],"\x20,\xC2,\xA0");
    $participante2 = trim($participante[1],"\x20,\xC2,\xA0");
    

    Now the whitespaces are removed correctly :3

    Thanks to all for give your help to solve this :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)