开发者

PHP inserting ellipsis in the middle(!) of a string?

开发者 https://www.devze.com 2022-12-09 09:44 出处:网络
I am working on a PHP forum software (FluxBB) and a user encountered a rather interesting error, that - so it seems - PHP is inserting an ellipsis in the middle of a string.

I am working on a PHP forum software (FluxBB) and a user encountered a rather interesting error, that - so it seems - PHP is inserting an ellipsis in the middle of a string.

Due to a similar error I found on the net I feel forced to say that this code is situated in a function and that $db is a global variable.

Here's the (simplified) code:

// Get unique words from the above arrays
$unique_words = array_unique(array_merge($words['add']['post'], $words['add']['subject']));

if (!empty($unique_words))
{
    $result = $db->query('SELECT id, word FROM '.$db->prefix.'search_words WHERE word IN('.implode(',', preg_replace('#^(.*)$#', '\'\1\'', $unique_words)).')', true) or error('Unable to fetch search index words', __FILE__, __LINE__, $db->error());

    $word_ids = array();
    while ($row = $db->fetch_row($result))
        $word_ids[$row[1]] = $row[0];

Now, $unique_words consists of multiple French words (in this case), and the ellipsis gets added right befor开发者_运维百科e the comma and behind the closing quote. That must mean it is added during the implode call, which makes no sense at all.

NOTE: Escaping the words is taken care of.

In fact, only PHP can be causing the error, since the query that is spit out by the debugger is saved before being executed.

I'm actually trying to give support, but I cannot come up with a reasonable solution...


We actually managed to fix it (or rather, figured out the problem). The problem was that one of the members who created these posts seemed to have writtem then in Microsoft Word or a similar program. As you probably all know, Word converts three dots into an ellipsis automatically. Therefore, the posts actually contained the ellipses.

Pasting that text into the forum created problems, because the preg_replace function seems to have some problems with utf-8 characters (as that seems to be one). Then again, they don't seem to be the only ones, since my patch didn't work either (and neither did a modified version to handle the other preg_replace).

Thanks to you, Volker, as you pointed me in the right direction.

0

精彩评论

暂无评论...
验证码 换一张
取 消