<?php
$urls = file('urls.txt');
foreach ($urls as $url) {
print(parse_url($url));
}
?>
parse_url takes string as argument but not array element with type string. What should I do?
There's no difference between a string and an array element of type string.
Your problem is most likely that file() by default includes in each array element the newline at the end of each line in the file. See:
http://php.net/manual/en/function.file.php
You're going to need to use FILE_IGNORE_NEW_LINES to make it not do this (see link for details)
You could take a different approach when reading the file. Take this example:
$fp = fopen('urls.txt', 'r');
while(($buffer = fgets($fp, 1024)) != NULL){
//where 1024 is maximum length of each line in file
if(gettype($buffer) == 'string'){
echo "$buffer\n";
}
}
fclose($fp);
Hope this helps you.
Notice: Array to string conversion ...