Create loop (like while) for each <li></li> inside a string

Discussion in 'PHP' started by Kyriakos, Apr 16, 2013.

  1. #1
    hi,
    I want to create a loop (like while) for each <li></li> inside a string.
    how i can do that?

    thanks in advance.
     
    Kyriakos, Apr 16, 2013 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    You need to post your code, but without it I would do something like this:

    
     
    <?php
    // list of items
    $list_items = '<li>List 1</li><li>List 2</li><li>List 3</li><li>List 4</li>';
    // use preg_split to look for </li> as delimeter
    $lists = preg_split('/(?<=<\/li>)(?!$)/', $list_items);
    // loop array
    for($i=0; $i < count($lists); $i++) {
       // print to screen
       echo $lists[$i].'<br />';    
    }
    ?>
    
    PHP:
     
    HuggyStudios, Apr 16, 2013 IP
  3. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    this is my code:
    <li><b>Operation System</b>: Embedded Linux</li>
    <li><b>Video</b>: 4CH. Analog</b>: BNC connector, IP</b>: Support up to 4CH</li>
    <li><b>Video outputs</b>: 2x BNC spot monitor outputs, 1x VGA output</li>
    <li><b>Video Compression</b>: H.264</li>
    <li><b>Video Streaming Format (IP)</b>: H.264/MPEG4/ MJPEG</li>
    <li><b>Recording Frame Rate</b>: CIF</b>: 120/100 fps; Half D1</b>: 120/100 fps; D1</b>: 60/50 fps</li>
    <li><b>Preview Resolution</b>: 1024 x 768</li>
    <li><b>Audio In/Out</b>: 4/1</li>
    <li><b>Ethernet</b>: 1, 10/100 Base-T, bandwidth-limited</li>
    <li><b>RS 232 / 485 Port</b>: 1/1</li>
    <li><b>USB 2.0 Ports</b>: 2</li>
    <li><b>Sensor In/ Relay Out</b>: 4/1</li>
    <li><b>Operator Interface</b>: USB mouse, USB PC keyboard, Remote controller</li>
    <li><b>Central Mnagement System</b>: CM3000/ CM3000 Gold (Up to 1000 DVRs), Remote iMatrix, Remote Console</li>
    <li><b>Remote DVR Connectivity</b>: WebViewer, JavaViewer, PDAViewer, SmartViewer, iPhoneViewer, iBBViewer, AndroidViewer</li>
    <li><b>HDD</b>: 1 SATA HDD &amp; 1 external e-SATA HDD (Support e-SATA RAID)</li>
    <li><b>Power Input</b>: Power adapter; 12V DC</li>
    <li><b>Dimensions</b>: 53 x 235 x 160 mm (H x W x D)</li>
    <li><b>Operating temperature</b>: 0° C to 40° C</li>
    Code (markup):
    it's not the same every time.
     
    Kyriakos, Apr 17, 2013 IP
  4. rudrawadi

    rudrawadi Greenhorn

    Messages:
    22
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #4
    create loop for each? I didn't get it, did you mean you want print all of them in loop and automatically put <li> tag around?
     
    rudrawadi, Apr 18, 2013 IP
  5. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #5
    I'm not sure what you mean, as long as there is a </li> at the end it will work.
     
    HuggyStudios, Apr 18, 2013 IP