zigojacko Posted March 18, 2014 Share Posted March 18, 2014 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. Link to comment https://forums.phpfreaks.com/topic/287045-struggling-with-the-correct-syntax-to-modify-a-return-value/ Share on other sites More sharing options...
Ch0cu3r Posted March 18, 2014 Share Posted March 18, 2014 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)); Link to comment https://forums.phpfreaks.com/topic/287045-struggling-with-the-correct-syntax-to-modify-a-return-value/#findComment-1472959 Share on other sites More sharing options...
zigojacko Posted March 18, 2014 Author Share Posted March 18, 2014 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 Link to comment https://forums.phpfreaks.com/topic/287045-struggling-with-the-correct-syntax-to-modify-a-return-value/#findComment-1472960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.