0

I have text file which looks like this:

http://www.books.com/imgs/b0388.jpg , ../../mdia/imp/books/b0388.jpg
http://www.books.com/imgs/b0369.jpg , ../../mdia/imp/books/b0369.jpg
http://www.books.com/imgs/b0309.jpg , ../../mdia/imp/books/b0309.jpg

Now I need to separate the url and the path with table columns with removing the comas of course (I want them in different table columns). After that I had to put buttons and forms at some right columns. My code is as follows:

<?php
$filename="listing.txt";
$fp=fopen($filename,'r');
if ($fp == FALSE){ 
        echo "File not opened";
        return 0;} 
//Default product name before administrator's modifications
$default="Product";
while ( ! feof( $fp ) ) {
   $line = fgets( $fp, 1024 );
   echo $line;
   echo $default;
   echo "<input type='text'></input>";
   echo "<button type='button'>Name product</button>";
   echo "<br/>";
}
fclose($fp);
?> 

1 Answer 1

2

Assuming each line is in the variable $line:

list($url, $path) = explode(',', $line);
//now use $url and $path to your heart's content

So if the line was:

http://www.books.com/imgs/b0388.jpg , ../../mdia/imp/books/b0388.jpg

So therefore it would become (after the above code):

$url == "http://www.books.com/imgs/b0388.jpg "
$path == "../../mdia/imp/books/b0388.jpg"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.