s1i2v3a
s1i2v3a

Reputation: 29

Simple PHP list of words to HTML ordered list

so my words is below, separated by space. my code is 1st line is grabbed from text file & whole line is echoed, instead i need each-word as ordered list.

• bombay new_delhi chennai culcutta

<?php
$z = file('q1.txt'); echo $z[1]; echo (mt_rand(1,9)); 

$st = array($z[1]);
foreach($st as $ls) {echo "  <li>$ls</li>\n";}

i need like this

• bombay

• new_delhi

• chennai

• culcutta

Upvotes: 0

Views: 445

Answers (3)

kishan
kishan

Reputation: 16

$var = file('q1.txt'); 
$abc = explode(' ', $var);

echo '<ul style=" list-style-type: circle;">';
foreach($abc as $value){
  echo " <li>$value</li>";
}
echo '</ul>';

Upvotes: 0

Rotimi
Rotimi

Reputation: 4825

Before the foreach()

echo '<ol>';
//foreach loop
echo '</ol>';

Upvotes: 1

s1i2v3a
s1i2v3a

Reputation: 29

<?php
$z = file('q1.txt'); echo $z[1]; echo (mt_rand(1,9)); 

$c=  explode(" ", $z[1]);
echo '<ol>';
foreach($c as $w) {echo " <li>$w</li>\n";}
echo '</ol>';

Upvotes: 0

Related Questions