简体   繁体   English

PHP-MySQL:使用特定字符限制数据

[英]PHP-MySQL: Limit data with a specific characters

I researched the forum but could not find a solution. 我研究了该论坛,但找不到解决方案。

I have a date in my DB and date format is not like Ymd H:i . 我的数据库中有一个日期,日期格式与Ymd H:i不一样。 And the table is not set as date. 并且该表未设置为日期。 I need to fetch the date from db but I just need Ymd . 我需要从数据库获取日期,但我只需要Ymd My date format like: 9.12.2014 18:34 . 我的日期格式为: 9.12.2014 18:34 I just need 9.12.2014 . 我只需要9.12.2014 I want my query to stop when it sees the blank/space. 我希望查询停止时看到空白/空格。 I'm fine with the dmY format. 我对dmY格式没问题。

Is there a way? 有办法吗?

This should account for most scenarios; 这应该说明大多数情况; you will get the whole string if there are no spaces: 如果没有空格,您将获得整个字符串:

SELECT IF(INSTR(field, ' ')=0, field, LEFT(field, INSTR(field, ' ')-1))
FROM the_table
;

I think I found the solution: 我想我找到了解决方案:

$email  = 'name@example.com';
$user = strstr($email, '@', true); // after PHP 5.3.0
echo $user; // name 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM