Jump to content

Recommended Posts

I am working on a script that will take the data of one array and put it into a new one.

All I'm sure about as of now it I will need a while loop. (Maybe?)

 

I have a form where you would post a list of search terms

<?php 
if (isset($_POST['songs'])) {
$list = $_POST['songs'];
$list = htmlentities($list);
$list = str_replace(" ", "%20", $list);
$list = explode("\n", $list);
print "<pre>";
print_r($list);
print "</pre>";
} else {
?>
<form method="post">
<input type="submit" value="submit" />
<textarea name="songs" id="songs" />
</form>
<?php
}
?>

 

Then it needs to go into this array

$feed_url = array(
'feed://gdata.youtube.com/feeds/api/videos?q=$list[0]',
'feed://gdata.youtube.com/feeds/api/videos?q=$list[1]',
'feed://gdata.youtube.com/feeds/api/videos?q=$list[2]',
'feed://gdata.youtube.com/feeds/api/videos?q=$list[3]',
'feed://gdata.youtube.com/feeds/api/videos?q=$list[4]', 
        // So on and so forth
);

 

The problem is this first array can be as short as one or possibly up to 1000 and I just want to see if you can do it dynamically or not

 

I know it's possible but I just can't figure it out on my own.

Can't you just use count() to see the size of the second array, and then use that value as the terminating value for a for loop.

 

Something like:

for($i = 0 ; $i <= count($arrayOne); $i++){

$arrayTwo = $arrayOne;

}

 

Please excuse any syntax mistakes, it's been a little while since I've done PHP programming, so I may have written that in a Java type format by mistake.. But that should be the general idea I would think.

 

Hope that helps

Denno

do is for echoing something and you did write it correctly :)

I tried a while loop but it used all my memory trying to do it. . .

while ($data = $list) 
{ 
  $SongList .= 'feed://gdata.youtube.com/feeds/api/videos?q='; 
  $SongList .= $data; 
  $SongList .= '&orderby=relevance\n'; 
} 

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.