PHP DOM Parser my html ul code

121 views Asked by At

I need help with my problem. I have this HTML code

<ul data-role="listview" data-inset="true" class="list-style-none ui-listview ui-listview-inset ui-corner-all ui-shadow">
    <li data-role="list-divider" class="ui-li ui-li-divider ui-btn ui-bar-b ui-corner-top ui-btn-hover-undefined ui-btn-up-undefined">

            VALUE1</li>

        <li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" data-opp="-666696165" data-odd="1.08">
                    <div class="ui-btn-inner ui-li" aria-hidden="true">
                       <div class="ui-btn-text">
                        <a href="#" class="container_12 ui-link-inherit">
                            <div class="grid_10">VALUEA1</div>
                            <div class="grid_2 right">VALUEA2</div>
                        </a>
                       </div>
                       <span class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span>
                      </div>
                    </li>
            <li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" data-opp="-666696166" data-odd="10.00">
                    <div class="ui-btn-inner ui-li" aria-hidden="true">
                       <div class="ui-btn-text">
                        <a href="#" class="container_12 ui-link-inherit">
                            <div class="grid_10">VALUEB1</div>
                            <div class="grid_2 right">VALUEB2</div>
                        </a>
                       </div>
                       <span class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span>
                      </div>
                    </li>
            </ul>

Problem is that I spend more than hours and any of my code doesnt work. Can you help me get this output ?

1: VALUE1

2: VALUEA1

3: VALUEA2

4: VALUEB1

5: VALUEB2

1

There are 1 answers

0
Benjamin Poignant On BEST ANSWER

U can use html parser or this method :

$html_values = explode(' ',preg_replace('`\s{2,}`',' ',trim(strip_tags($html))));
//1 strip_tags : remove html tags
//2 trim : remove space right and left 
//3 preg_replace : remove useless space
//4 explode: make an array 
foreach($html_values as $index=>$value){
    echo $index.': '.$value.'<br />';
}

Show :

0: VALUE1
1: VALUEA1
2: VALUEA2
3: VALUEB1
4: VALUEB2