输出空字符串- php

时间:2022-06-25 00:01:43

Hi I am performing an SQL query (that only returns one row) and I am printing a particular column on screen just for test purposes. The problem I am having is, the column that I am printing contains a string of 12 characters (abcdef123456), yet sometimes the printed variable is empty. So when I do var_dump($test);

你好,我正在执行一个SQL查询(它只返回一行),我在屏幕上打印一个特定的列只是为了测试。我遇到的问题是,我正在打印的列包含12个字符的字符串(abcdef123456),但有时打印的变量是空的。当我做var_dump($test)时;

sometimes I get:

有时我得到:

string(12) "abcdef123456"

but some other times I get

但有时我得到

string(12) ""

I dont understand why it knows there are 12 characters yet its still empty, and sometimes it says 12 characters yet its full. Due to this, I cant perform other functions as they rely on the string.

我不明白为什么它知道有12个字符,但它仍然是空的,有时它说12个字符,但它是满的。由于这个原因,我无法执行其他依赖于字符串的函数。

EDIT: here is the query

编辑:这是查询

$query="SELECT * FROM members WHERE name='$member'";
$sqlResult=mysql_query($query);
$row = mysql_fetch_assoc($sqlResult);
$test = $row["membercode"];
var_dump($test);

3 个解决方案

#1


1  

You most-likely have html tags in your string that are being rendered by the browser.

您很可能在您的字符串中有由浏览器呈现的html标记。

$foo = "<p><img><div><table>";
var_dump($foo); // string(20) ""

#2


2  

Where do you see that it says string(12) ""? Remember to ALWAYS look in the raw output; the source code. Not how the browser renders it.

你在哪里看到它说字符串(12)“”?记住要始终查看原始输出;源代码。而不是浏览器如何呈现它。

For instance, if the string is <span></span>, that'll show up as nothing.

例如,如果字符串是,则显示为无。

#3


1  

  1. Try adding header('Content-Type: text/plain') to render your page as text instead of HTML. Or use "View Source" to view the HTML source instead of the rendered page. There may be hidden HTML tags in the string.

    尝试添加标题('Content-Type: text/plain')来将页面呈现为文本,而不是HTML。或者使用“视图源”来查看HTML源而不是呈现的页面。字符串中可能有隐藏的HTML标记。

  2. Try var_dump(bin2hex($test)). There may be invisible control characters such as "\0" that you can't see. For example:

    尝试var_dump(bin2hex(测试)美元)。可能有一些不可见的控制字符,如“\0”,您看不到。例如:

    $ php <<< '<?php var_dump("\0\0\0\0"); ?>'
    string(4) ""
    $ php <<< '<?php var_dump(bin2hex("\0\0\0\0")); ?>'
    string(8) "00000000"
    

#1


1  

You most-likely have html tags in your string that are being rendered by the browser.

您很可能在您的字符串中有由浏览器呈现的html标记。

$foo = "<p><img><div><table>";
var_dump($foo); // string(20) ""

#2


2  

Where do you see that it says string(12) ""? Remember to ALWAYS look in the raw output; the source code. Not how the browser renders it.

你在哪里看到它说字符串(12)“”?记住要始终查看原始输出;源代码。而不是浏览器如何呈现它。

For instance, if the string is <span></span>, that'll show up as nothing.

例如,如果字符串是,则显示为无。

#3


1  

  1. Try adding header('Content-Type: text/plain') to render your page as text instead of HTML. Or use "View Source" to view the HTML source instead of the rendered page. There may be hidden HTML tags in the string.

    尝试添加标题('Content-Type: text/plain')来将页面呈现为文本,而不是HTML。或者使用“视图源”来查看HTML源而不是呈现的页面。字符串中可能有隐藏的HTML标记。

  2. Try var_dump(bin2hex($test)). There may be invisible control characters such as "\0" that you can't see. For example:

    尝试var_dump(bin2hex(测试)美元)。可能有一些不可见的控制字符,如“\0”,您看不到。例如:

    $ php <<< '<?php var_dump("\0\0\0\0"); ?>'
    string(4) ""
    $ php <<< '<?php var_dump(bin2hex("\0\0\0\0")); ?>'
    string(8) "00000000"