I have a piece of code that extracts delilminated text from a text file and puts it onto a HTML page.

The code is below and here is the page. I'm trying to get the str_replace function to get the " out of the text file but it doesn't seem to work and this is why my pictures are not showing. Instead of www.????/CITY_082408.jpg I get www.???/"CITY_476474.jpg as the URL. The code below extracts " out of the text file too as it is at the beginning of each line. I tried the below but it didn't work. Any ideas?

Thanks

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#86B3C8" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="5" height="100%">
<tr align="center" valign="middle">
<td align="left">
<table width="300" border="1" cellspacing="0" cellpadding="3" bordercolor="#000000">
<tr>
<td><font color="#000000" face="Verdana, Arial, Helvetica, sans-serif" size="2">
<?php
$array = file("xfile.txt");

foreach($array as $row) {
$line = explode('","', $row);


$search = array('"');
$replace = array('');
$array = str_replace($search, $replace, $array);

print "<b>Address:</b> $line[2] <br><b>Post Code:</b> $line[5] <br> <b>Price:</b> £$line[7] <br><b>Description:</b> $line[38]<br><img src=http://www.londonorient.com/$line[0]_$line[1].jpg><br><br><hr align='left' width='100%'><br>";
}
?>
</font> </td>
</tr>
</table>

</td>

</tr>
</table>
</body>
</html>

    Try this
    $search = '\"';
    $replace = ''; /these are two single quotes
    $array = str_replace($search, $replace, $array);

      No good Im afraid. The code doesnt through up an error yet as you can see from the new file it still adds " to the URL and now that I have told it to echo "line[0]" you can see the " before BRANCHID.

      Any more ideas? Thanks for your help thus far.

      FILE URL

      New Code reads:

      <?php
      $array = file("xfile.txt");

      foreach($array as $row) {
      $line = explode('","', $row);

      $search = '\"'; 
      $replace = ' '; 
      $row = str_replace($search, $replace, $row);

      print "$line[0] <br><b>Address:</b> $line[2] <br><b>Post Code:</b> $line[5] <br> <b>Price:</b> £$line[7] <br><b>Description:</b> $line[38]<br><img src=http://www.londonorient.com/$line[0]_$line[1].jpg><br><br><hr align='left' width='100%'><br>";
      echo strtr($line[2], '"', ' ');
      }
      ?>

      I tried this with £array and $row by the way.

        This small piece of code seemed to solve the problem. It's not a good idea to strip all "´s from a file, so I let the needle in str_replace be a bit more accurate:

        $filename = 'http://www.londonorient.com/lettings2.php';
        $fpArr = file($filename);
        
        $fpArr = str_replace('/"','/',$fpArr);
        
        for($i=0;$i<count($fpArr);$i++)
        {
        	echo nl2br($fpArr[$i]."\n");
        }
        

        so ... I replace /" with / whick should solve your problem. The pictures though, do not seem to exist ...

          Write a Reply...