I have just uplaoded a beta version of the site: http://www.tubeshine.com Tell me what you think. I REALLY need to find a way to validate the fields so that if they don't contain youtube.com then the form wont submit. I am also thinking about giving each IP a session and if they try to submit too many times it will just deny them -- and some other things. Maybe capcha, because there's no registration or emails required on this site. People can just come along and add all the lists they want. It wont hurt none if they add stupid lists or error code, because it doesn't show on the site. But I'd like to try and keep the server clean if possible. I am going to go and implement that code above on my localhost now.. see if I can get it working. How to I go about this? if ( url contains youtube.com ) { I put my regular code here } else { ENTER A YOUTUBE URL! }
Sorry nico_swd, the code is so foreign to me, I didn't realise that you gave me the answer. When I looked at that code I thought it was only to get rid of the explodes. I feel la bit dim now :/ In my defense, I was very tired. I have had a sleep now and I am getting back to implementing all the code that was suggested. One of the things I have to do is try to figure out "why" the code does what it does so I can remember for the future. I have a real hard time remembering a lot of programming, and even the programming I "can" do took me a very long time to learn and remember. But I am getting better! ..slowly, lol
I am trying to implement this code now, but it is not being placed in the text file. Originally I had like: $listf = fopen ($_SERVER['DOCUMENT_ROOT'] . '/videos/'.$_POST['new_video'].'.txt', 'w+'); if ($_POST['v01'] != '') { $original_url = $_POST['v01']; $split_url = explode('v=', $original_url); $split_url_again = explode('&', $split_url[1]); $string = "".$split_url_again[0]."\n"; } etc etc etc fwrite($listf,$string); fclose($listf); header('Location: /code.php?v='.$_POST['new_video'].''); Code (markup): So I tried: $listf = fopen ($_SERVER['DOCUMENT_ROOT'] . '/videos/'.$_POST['new_video'].'.txt', 'w+'); foreach ((array)$_POST['v'] AS $v) { #echo $v; $string = "".$v."\n"; } fwrite($listf,$string); fclose($listf); header('Location: /code.php?v='.$_POST['new_video'].''); Code (markup): It created the text file, but it didn't put anything in it. The old way I had it, basically it just gets all the youtube ID's out of the form and posts them one after the other like this: XLh4-XTnXq8 5z0F0CzMPrE jwsHrst8Grw mCLmFtu_O1Q hPRcJE6k1io -m19mzFObvU sTpEyZtPbOs l2ki6jr624Q GycEVtNRVhI XUoua5ef63A pMl4KCA9YcQ Code (markup): How can I made the new code do that? I have it all set up and I have removed all my old code, but I just need to know how to write the information to the text file. I know how to do it the way I was doing it (took me months just to learn that lol).. but this way it isn't writing.
Specifically: foreach ((array)$_POST['v'] AS $v) { #echo $v; $string = "".$v."\n"; } Code (markup): This is the part I don't know how to make written to the new file. Maybe I have to have something like: $string = "foreach ((array)$_POST['v'] AS $v)"; Code (markup): ?
I got it to print a word into the text file: Array Code (markup): This is how I made the code. I think I am on the right track, but I am running out of patience. foreach ((array)$_POST['v'] AS $v) { $v[0] = $v[0]; $v[1] = $v[1]; } Code (markup): I am still trying.. *sigh* I think I might just go back to the way I had it. My skills just aren't good enough to get all fancy. It did the job.
I got it working: $listf = fopen ($_SERVER['DOCUMENT_ROOT'] . '/videos/'.$_POST['new_video'].'.txt', 'w+'); foreach ((array)$_POST['v'] AS $v) { $v = "".$v."\n"; fwrite($listf,$v); } fclose($listf); header('Location: /code.php?v='.$_POST['new_video'].''); Code (markup): I just kept trying everything I can think of until it worked. I really have no idea how it works though It worked after I put the fwrite INSIDE the foreach brackets. I figured it should go in there because the echo was displaying all the lines, so why wont it just write it? So I figured -- well I'll just put the fwrite in there and see what happens. Then it worked. Man it's really hard to get stuff working when you don't understand the code.
Now I am trying to put the fancy youtube.com detect code in there. Am I on the right lines here? foreach ((array)$_POST['v'] AS $v) { $v = "".$v."\n"; $numFields = 20; $originalUrls = array(); for ($i = 0; $i < $numFields; $i++) { if (preg_match('~^http://(?:[a-z]{2,3}\.)?youtube\.com/watch\?v=([\w-]+)~', $_POST['v'][$i], $match)) { $originalUrl[$i] = $match[1]; } else { $originalUrl[$i] = 'EMPTY'; } } fwrite($listf,$v); } Code (markup): I'll play around with it until someone answers. Hopefully I can figure it out myself.
ok I figured it out. I was trying to use 2 codes at once - duh, lol. This is what I needed: for ($i = 0; $i < $numFields; $i++) { if (preg_match('~^http://(?:[a-z]{2,3}\.)?youtube\.com/watch\?v=([\w-]+)~', $_POST['v'][$i], $match)) { $originalUrl[$i] = $match[1]; $v = "".$originalUrl[$i]."\n"; fwrite($listf,$v); } else { $originalUrl[$i] = 'EMPTY'; } } Code (markup): Now I am right back to where I started. I need to figure out how to detect if youtube.com is present in the URL. If NOTHING is entered, that's all fine. But if "something" is entered but doesn't contain "youtube.com" I want it to say "Please enter an valid URL" or something. ie: if ( url contains youtube.com ) { I put my regular code here } else { ENTER A YOUTUBE URL! } Code (markup): I might be able to put a header location in where it says: [codde] else { $originalUrl[$i] = 'EMPTY'; } [/code] or something. I'll go and try that now.
I just want to say -- thanks heaps for all of you that helped me do this. I am so useless at programming. Thanks for putting up with me. But at least now I have implemented all the code you suggested. I suppose it doesn't really matter too much if the page doesn't say: "Please enter a valid URL".. and the form just writes NOTHING to the file. That amounts to the same thing I guess. The only real problem is people submitting a totally blank form. But I think I can fix that another way by saying something like if $_POST['submit'] != THEN end or return or make a new header location or SOMETHING. I donno, but I think I'll figure it out. I figure all the above out. I have no idea how lol -- but I did