Jump to content

Struggling with the correct syntax to modify a return value


zigojacko

Recommended Posts

This is the function I am currently working with... 

    /**
     * Retrieve search query text
     *
     * @return string
     */
    public function getQueryText()
    {
        if (!isset($this->_queryText)) {
            $this->_queryText = $this->_getRequest()->getParam($this->getQueryParamName());
            $noescape = preg_replace("/%u([0-9a-f]{3,4})/i","\\1;",urldecode($this->_queryText));
            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));
				 
				echo '<span style="display: none;">';
				echo '<pre>';
					var_dump (
						$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;
    }

I can echo what I need to output in this function with $noescape however I need to modify return $this->_queryText; to include the preg_replace and rawurldecode from $noescape.

 

Please could someone be kind enough to advise of the correct syntax/way of handling this? I did post this on StackOverflow but had no response as of yet.

 

Thanks in advance.

What is the purpose of $noescape? If you want the result of returned from preg_replace to be applied to $this->_queryText then there is no need for $noescape.

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

 

What is the purpose of $noescape? If you want the result of returned from preg_replace to be applied to $this->_queryText then there is no need for $noescape.

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

Sorry, I forgot to mention that the other way I looked at was how you've suggested.

 

You're right, $noescape serves no other purpose and what you're supplied is exactly what I was trying to do (just was unsure of the correct syntax but now looks so simple). Thanks very much :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.