您好,我需要从文本文件中提取一些图像链接。 它应该存储在一些变量中,以便链接可以重复使用。 我只需要在img文件与image1.jpg结束PHP读取字符串,直到文本文件中
我用这个代码
<?php
$myfile = fopen("vwe/autos.inc", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
$photo1 = fgets($myfile);
//echo var_export(substr($photo1, 0, 30))."<br>";
echo "1)".substr($photo1, 10, 30)."<br>";
echo "2)".substr($photo1, 40, 80)."<br>";
}
close($myfile);
?>
Autos.inc看起来像这样:
<div class='glidecontent'>
<div id='positiontest'>
<a href='occasion.aspx' target='_self'>
<img src='http://site.nl/643607012/image1.jpghttp://sit.nl/643607013/image2.jpghttp://site.nl/643607014/image3.jpg' width='100%' border='0' height='100%' style='float: top; padding: 0px' />
</a>
<div id='textonadd'>
<b>Citroën C3</b> 1.4i Différence</br>
Bouwjaar: 2004 | Prijs: 3250 euro
</div>
</div>
</div>
<div class='glidecontent'>
<div id='positiontest'>
<a href='occasion.aspx' target='_self'>
<img src='http://site.nl/643587726/image1.jpghttp://site.nl/643587727/image2.jpghttp://site.nl/643587728/image3' width='100%' border='0' height='100%' style='float: top; padding: 0px' />
</a>
<div id='textonadd'>
当前代码会发生什么?另外,最后一个函数应该是'fclose',除非你写了'close'函数.. – chris85
嗨,你是对的,这是一个错字,当前的代码不工作,因为它不被视为1个文本字符串,每行都有缺少信息,而不仅仅是在文件的开头。 –