Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:17:11+00:00 2026-06-09T13:17:11+00:00

I thought this would be easy, but turning out to be hard. All I

  • 0

I thought this would be easy, but turning out to be hard. All I am trying to do is replace a value in an object then print out the changed string. This is within Joomla, by the way. Not that it matters, just to explain all the JHTML/and JURi stuff in the code.

The code that I have been trying is…

<?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;

?>

So my str_replace line is where I’m having the problems. $this->containers is just an array of states and other stuff echoes out a dropdown box. I tried to do the replace before it echoes out on the last line, but the words “Your Favorite Places” are still there. Do I have to put this in a foreach loop or something similar?

Here is a partial print_r (in fact the string I want to replace is in it. Category Title => Your Favorite Places)

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
    )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:17:12+00:00Added an answer on June 9, 2026 at 1:17 pm

    Property $this->containers is an array of objects.

    You’ll need to iterate through this array, access each object’s title property, and replace that property’s string value (if it is the correct string).

    So…

    Get rid of this block:

    $items = str_replace("Your Favorite Places", "Browse By Region", $this->containers);
    

    Replace it with this line:

    $items = array(); // Create an array to load the objects in as values.
    foreach($this->containers as $object) { // Iterate through $this->containers, which is an array. Load the object into temporary variable $object.
        if (strpos($object->title, 'Your Favorite Places') !== false) { // If the title property contains a string you're looking for, replace it with the value you want.
            $object->title = str_replace('Your Favorite Places', 'Browse By Region', $object->title);
        }
        if (strpos($object->indented, 'Your Favorite Places') !== false) { // Should work with any property value with whitespaces also.
            $object->indented = str_replace('Your Favorite Places', 'Browse By Region', $object->indented);
        }
        $items[] = $object; // Load the object into array $items.
    }
    

    Edit: I’ve added a way to check for part of the string rather than the whole string, and to replace the partial string match in order to preserve whitespaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this would be pretty easy but I'm running into all sorts of
I thought this would be fairly easy, but I'm totally baffled. I want one
I would have thought that this would be an easy thing to do, but
I thought this would be fairly simple but it turns out not to work
I thought this would be relatively easy but running it, gives wrong result. It
I would have thought this would be an easy one to Google, but I've
I thought this would be an easy one for me to figure out (or
I thought this would be easy to find, but a google search has been
I thought this would be insanely easy but I'm stumped. I want to take
I thought this would be an easy thing but many hours have gone by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.