Jump to content

Struggling with the correct syntax to modify a return value


Go to solution Solved by Ch0cu3r,

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.

  • Solution

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));
Edited by Ch0cu3r

 

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 :)

Edited by zigojacko
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.