来自mysql_fetch_array的空间正在破坏我的链接


Spaces coming from mysql_fetch_array are corrupting my links

$oku = mysql_fetch_array($yaz);
echo $oku[0];

这将打印我的$oku[0]值,例如hello world

但是如果我像这样使用它:

echo "<a href=index.php?member=" . $oku[0] . ">" . $oku[0] . "</a>";

它以文本形式完全正确地显示了 hello 世界,但链接转到 index.php?member=hello

它不包含空格后面的文本。如何解决这个问题?

使用 php rawurlencode-function 对字符串进行编码(其中包含空格)

只需执行以下操作:

printf(
    '<a href="%s">%s</a>',
    'index.php?member=' . rawurlencode($oku[0]),
    $oku[0]
);