Displaying Multiselect Data without Delimiters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • minimalPixel
    New Member
    • Nov 2008
    • 2

    Displaying Multiselect Data without Delimiters

    Hi All,

    Sorry for the noob question, but hopefully this is an easy one.

    I'm not exactly sure if this is a php or a mysql question, but I'm working with a component in Joomla's backend that allows a user to choose one or many options from a multiselect form. Then, I'm calling the data (not the form) and displaying it as content in the frontend.

    The bummer part is that when it's displayed on the frontend, the delimiters are displayed too, like so:

    Data: option1|*|optio n2|*|option3|*| option5

    Is there a way I can replace the "|*|" delimiters with "<br />" at the very least, or "<li>option </li>" when it's called on the frontend?

    Thanks for your help!

    -James
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I didn't understand half the problem, but if you still have php working, you can use the str_replace() function.

    regards

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      str_replace() would work, but not for the <li> attempt.

      Consider the following:

      Code:
      <?php
      	
      $string = "option1|*|option2|*|option3|*|option4|*|option5";
      
      // creates an array using delimiter
      $string_array = explode("|*|", $string);
      
      echo "<select>\n";
      
      // loop through array for output
      foreach( $string_array as $option )
      {
      	echo "\t<option>{$option}</option>\n";
      }
      
      echo "</select>";
      	 
      ?>

      Comment

      • minimalPixel
        New Member
        • Nov 2008
        • 2

        #4
        Awesome. Thanks a lot for your help. the str_repace function should do the trick.

        Cheers,

        James

        Comment

        Working...