如何从PHP中删除html字符串中的换行符?

时间:2015-08-15 06:17:58

标签: php html sql arrays string

我的问题是,当我尝试追加“[+]”字符串时,它会自动添加换行符。如何在同一条线上显示?

我希望它像这样显示

function diff($old, $new) {
    $matrix = array();
    $maxlen = 0;
    foreach ($old as $oindex => $ovalue) {
        $nkeys = array_keys($new, $ovalue);
        foreach ($nkeys as $nindex) {
            $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ?
                    $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
            if ($matrix[$oindex][$nindex] > $maxlen) {
                $maxlen = $matrix[$oindex][$nindex];
                $omax = $oindex + 1 - $maxlen;
                $nmax = $nindex + 1 - $maxlen;
            }
        }
    }
    if ($maxlen == 0) {
        return array(array('d' => $old, 'i' => $new));
    }

    return array_merge(
            diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}

function htmlDiff($old, $new) {
    $currentuser = $_SESSION['username'];
    $ret = '';
    $display_old = '';

    $diff = diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new));

    foreach ($diff as $k) {
        if (is_array($k)) {
            $ret .= (!empty($k['d']) ? "<del style=\"background: highlight;\">" . implode(' ', $k['d']) . "</del>" . " (Last Edited by: " . "$currentuser)" : '') .
                    (!empty($k['i']) ? "<ins style=\"background:highlight;\">" . implode(' ', $k['i']) . "</ins>" . " (Last Edited by: " . "$currentuser)"  : '');
        } else {
            $ret .= $k . ' ';
        }
    }
    return $ret;
}
?>

我的代码在比较新旧字符串

后返回字符串
{{1}}

0 个答案:

没有答案