I have a function called listelements()
, which outputs text like <li>text1</li><li>text2</li>
.
I have more than 500 elements. Now I want to convert it into an array.
Can anyone help me? Thanks.
Note: I’m using php
Update:
The thing i want to achieve is alphabetical navigation. As of now my function displays links in list order. Instead of that i want to hold that in an array. Then i would like to filter them using characters.
$valid_characters = range( 'a' , 'z' ); $valid_numbers = array(1,2,3,4,5,6,7,8,9,0);
When the user click “A” i would like to display only links start with A. Hope this explanation helps you guys for better understanding my question
Advertisement
Answer
<?php $output = listelements(); $array = explode("<li>", $output); //First element will be empty, so remove it unset($array[0]); // Now remove "</li>" at end of input array_walk($array, create_function('&$val', '$val = str_replace("</li>", "", $val)')); // $array should now contain your elements