我以为这很容易,但结果很难。我要做的就是替换对象中的一个值,然后打印出更改后的字符串。顺便说一句,这是在 Joomla 中。这并不重要,只是为了解释代码中的所有 JHTML/和 JURi 内容。
我一直在尝试的代码是......
<?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
)