正确的语法将变量传递给对象或修改对象以包含preg_replace

时间:2014-03-17 16:51:41

标签: php variables object syntax preg-replace

如果标题的措辞不正确,我会道歉但我现在可以输出我想要的内容: -

$noescape = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText));

然后通过var转储以下内容: -

$noescape

现有功能的最终输出是: -

return $this->_queryText;

我需要修改_queryText以使用$noescape或包含上面的preg_replace ...

我不确定我是否可以按照以下方式对return $this->_queryText;进行语法修改: -

return $this->preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText));

return $noescape($this->_queryText);

或者我是否需要修改函数的另一部分(下面的整个函数): -

/**
 * Retrieve search query text
 *
 * @return string
 */
public function getQueryText()
{
    if (!isset($this->_queryText)) {
        $this->_queryText = $this->_getRequest()->getParam($this->getQueryParamName());
        if ($this->_queryText === null) {
            $this->_queryText = '';
        } else {
            /* @var $stringHelper Mage_Core_Helper_String */
            $stringHelper = Mage::helper('core/string');
            $this->_queryText = is_array($this->_queryText) ? ''
                : $stringHelper->cleanString(trim($this->_queryText));

            $noescape = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText)); 
            echo '<span style="display: none;">';
            echo '<pre>';
                var_dump (
                    //$this->rawurldecode($this->getQueryText())
                    $noescape
                );
                echo '</pre>';
            echo '</span>';

            $maxQueryLength = $this->getMaxQueryLength();
            if ($maxQueryLength !== '' && $stringHelper->strlen($this->_queryText) > $maxQueryLength) {
                $this->_queryText = $stringHelper->substr($this->_queryText, 0, $maxQueryLength);
                $this->_isMaxLength = true;
            }
        }
    }
    return $this->_queryText;
    //return $this->preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText));
    //return $noescape($this->_queryText);
}

希望有道理......

1 个答案:

答案 0 :(得分:0)

好的,其他人已经设法为我指出了这一点......

return $this->_queryText = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->_queryText));

完美地工作。