我認爲這很容易,但變得很難。所有我想要做的是替換對象中的值,然後打印出更改的字符串。順便說一句,這在Joomla內。這並不重要,只是爲了解釋代碼中的所有JHTML /和JURi內容。替換對象數組中的字符串PHP
,我一直在努力的代碼是...
<?php
// Display the child select box.
if (isset($this->containers) && count($this->containers)):
$items = str_replace("Your Favorite Places", "Browse By Region", $this->containers);
echo JHtml::_('select.genericlist', $items, 'finder-containers','onchange="document.location=this.value; return false;"', 'link', 'indented', JUri::getInstance()->toString(array('path')));
endif;
?>
所以我str_replace
線就是我有問題。 $this->containers
只是一個狀態數組和其他東西回聲出下拉框。我試圖在最後一行發出回聲之前進行替換,但「你最喜歡的地方」這個詞仍然存在。我必須把這個放在foreach
循環或類似的東西嗎?
這裏是一個局部的print_r(其實我想替換字符串是它。分類標題=>你喜歡的地方)
Array (
[0] => stdClass Object (
[category_id] => 1
[title] => Gallery
[alias] => gallery
[slug] => 1:gallery
[level] => 0
[my_items] => 0
[url] => index.php?option=com_gallery&view=images&category_id=1
[route] => index.php?option=com_gallery&view=images&category_id=1:gallery&Itemid=1766
[link] => /your-favorite-places/categories/gallery.html
[indented] => Gallery
)
[1] => stdClass Object (
[category_id] => 164
[title] => Your Favorite Places
[alias] => your-favorite-places
[slug] => 164:gallery/your-favorite-places
[level] => 1
[my_items] => 0
[url] => index.php?option=com_gallery&view=images&category_id=164
[route] => index.php?option=com_gallery&view=images&category_id=164:gallery/your-favorite-places&Itemid=3711
[link] => /your-favorite-places/gallery.html
[indented] => Your Favorite Places
)
[2] => stdClass Object (
[category_id] => 87
[title] => North America
[alias] => north-america
[slug] => 87:gallery/your-favorite-places/north-america
[level] => 2
[my_items] => 0
[url] => index.php?option=com_gallery&view=images&category_id=87
[route] => index.php?option=com_gallery&view=images&category_id=87:gallery/your-favorite-places/north-america&Itemid=1775
[link] => /your-favorite-places/north-america.html
[indented] => North America
)
我們可以看到一個var_dump($ this-> containers)嗎? – ernie 2012-08-09 22:40:56
你正在使用'str_replace'和一個數組? – alfasin 2012-08-09 23:12:45
我認爲這是做到這一點的方法。無論如何,我會採取行動,只是用區域瀏覽來代替這三個詞 – decaye 2012-08-09 23:26:18