开发者

Parsing multiple files from a folder and fetching the content as variables

I am sure a silly question for you but a big one for me as I have just started learning programming.

My issue is like this:

I have multiple HTML files in a folder. Each file has 3 values in 3 lines (only 1 item in each line).

Line 1 : Title
Line 2 : Image Link
Line 3 : Details

I want to import these files to a jQuery based Ajax Tabs Script, I have and the XHTML part of it is like this:

<ul class="mytabs" id="tabs">
    <li class="current"><a href="./tabs/tab-1.html">Tab 1</a></li>
    <li><a href="./tabs/tab-2.html">Tab 2</a></li>
    <li><a href="./tabs/tab-3.html">Tab 3</a></li>
    <li><a href="./tabs/tab-1.html">Tab 4</a></li>
    <li><a href="./tabs/tab-2.html">Tab 5</a></li>
    <li><a href="./tabs/tab开发者_Go百科-3.html">Tab 6</a></li>

</ul>
<div class="mytabs-container" id="tabs-container">
    Loading. Please Wait...
</div>

What I want is to parse these HTML files and the Title in Tab's Name position, Image Link and Details in the Tab Container and The link to that file in the href before tabs title so that the final product looks something lkike this:

<ul class="mytabs" id="tabs">
    <li><a href=<?php echo $linkToFile?>><?php echo $title ?></a></li>
</ul>
<div class="mytabs-container" id="tabs-container">
    Loading. Please Wait...
    <?php echo $imageLink?>
    <?php echo $details?>
</div>

I need a PHP or jQuery script which should do the following:

  1. Loop and get the contents of all the HTML files from the folder
  2. Fetch content in the form of a variable so that I can placed them as shown above.
  3. Fetch the link to file too as a variable so that it can also be placed as the link to tabs.

Is this possible? If yes how can I achieve that.

Kindly help.


well, then, if you want to read a file in php, you can use something like:

$myfile = 'info.htm';
$lines = file($myfile);   
$info = array('title'=>$lines[0], 'image'=>$lines[1], 'details'=>$lines[2]);
echo '<h1>'.$info['title'].'</h1>
      <img src="'.$info['image'].'" alt="'.$info['title'].'"/>
      <p>'.$info['details'].'</p>';

obviously, you have to run that for every .htm file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜