Correct syntax to either pass a variable into an object or modify object to include preg_replace

81 views Asked by At

Apologies if the title is not correctly worded but I can currently output what I am after with:-

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

And then by var dumping the following:-

$noescape

The final output in the existing function is:-

return $this->_queryText;

I need to modify _queryText to use either $noescape or include the preg_replace above...

I'm unsure whether I can syntactically modify return $this->_queryText; along the lines of:-

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

or

return $noescape($this->_queryText);

Or whether I'd need to look at modifying another section of the function (entire function below):-

/**
 * 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);
}

Hope that makes sense...

1

There are 1 answers

0
zigojacko On BEST ANSWER

Okay, someone else has managed to point this out for me now...

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

Working perfectly.