Jump to content

Loop from a text fle


Guest MrLeN

Recommended Posts

Guest MrLeN

<iframe id="fr" src="http://www.youtube.com/subscribe_widget?p=USERNAME" style="overflow: hidden; height: 105px; width: 300px; border: 0;" scrolling="no" frameBorder="0"></iframe>

 

The above code allows me to display a subscribe widget for YouTube. However, I want to put it in a php loop and display USERNAME from a text file.

 

And I will make a text file like this:

 

username1
username2

 

How can I make a loop and make the loop display all the names in the text file?

 

Can someone please show me the code?

 

I know how to do a loop. It explains here:

 

http://www.w3schools.com/php/php_looping_for.asp

 

But I don't know how to make the loop get the lines out of the text file.

 

Can someone help please?

Link to comment
Share on other sites

<?php

$names = file('/path/to/file/names.txt');
foreach ($names as $name) {
  echo '<iframe id="fr" src="http://www.youtube.com/subscribe_widget?p=' . $name . '" style="overflow: hidden; height: 105px; width: 300px; border: 0;" scrolling="no" frameBorder="0"></iframe>';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.