I have the following PHP Code:
<?php
$file = "Links.txt";
$parts = new SplFileObject($file); // this is your array of words
foreach($parts as $word) {
$content = file_get_contents($word);
parse_str($content, $ytarr);
echo $ytarr['title'];
unset($content);
}
?>
Please note:
- The Links.txt file includes multiple external URL's, on each line is only one URL. Example:
www.External-URL-number-ONE.com
www.External-URL-number-TWO.com
www.External-URL-number-THREE.com
- Each of this URL have the 'title' item in the variable $content (after filling it by "file_get_contents($word);".
- For troubleshooting purpose, I tested each URL by adding it in the "links.txt" single. The result was for each URL successful. The issue occours, if I add multiple URL's. In that case, the behavior is:
Error message and result:
Notice: Undefined index: title in C:\xampp\htdocs\PHPexample\index.php on line 13
Display the Title of "www.External-URL-number-THREE.com"
How can I fix this problem? It should work also with multiple lines.
Thanks in advance.
EDIT:
The content of the variable $content
is:
Array (
[reason] => Invalid parameters. [status] => fail [errorcode] => 2
)
Array (
[ISD] => 928398 [enable] => 1 [list] => 39/9339/30 [AMP] => [host] => [title] => This_Is_the_Title_Three [token] => 1
)
UPDATE
I have used the isset() for checking the array before access it. And only the last for each loop have an index.