Jump to content

PNewCode

Members
  • Posts

    315
  • Joined

  • Last visited

Everything posted by PNewCode

  1. @gizmola You nailed it! And to @requinix I just realized from Gizmola's reply that I originally gave the wrong part of my code. I apologize for that. I thought the line that I provided was where my issue was. Apparently not. So for my education, if you don't mind... The reason Gizmola's worked is because it's the first part of a 3 section translation? First being domain, second being the (watch, si, etc) and then the last being the ID? Thats what it looks like to me now. I couldn't see that before. And looks as though they are separated by the " | " character? That really helped me a lot to better understand this. Thank you. Am I correct in my understanding of how it works?
  2. I've been giving this a solid effort and still stuck. But I'm no further along since my last post. Any thoughts?
  3. @requinix Here's the whole thing. It may not make sense (maybe?) because there's a lot of other stuff on the page (very long) that goes with everything involved for the user. But basically... the user enters a youtube link in a form. Then that form is sent to the (link-insert.php) which sends that link along with the title of the youtube link to the database (example: The link for the music video Korn - Life is peachy will send that title to the database) What I have originally works for shared links (youtu.be?si=) and regular links (youtube.com/watch?v=) and also songs from playlists. However if someone sends a link that is a short (youtube.com/shorts/VIDEO-ID-HERE) sends back a blank entry to the database as the title because it can't translate that link extension Note: $link is the field namd in the form $band is the column in the database The following also successfully allows the thumbnail to show on the page that calls the info from the database The shorts is the only thing that will send a blank entry to $band into the database ($band is the title of the video) You'll notice the last part, is the part I'm having the trouble with EDIT: Also, if it's not a youtube link at all, then "Not a youtube request" enters in $band in the database so that it's not blank $ytvideo1 = $link; $linkurl = "$ytvideo1"; parse_str( parse_url( $linkurl, PHP_URL_QUERY ), $vid ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $linkurl, $match); $youtube_id = $match[1]; $preurl = "https://www.youtube.com/watch?v=$match[1]"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $preurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $document = htmlspecialchars($output); curl_close($ch); $line = explode("\n", $document); $judul = ""; foreach($line as $strline){ preg_match('/\<title\>(.*?)\<\/title\>/s', $strline, $hasil); if (!isset($hasil[0]) || $hasil[0] == "") continue; $title = str_replace(array("<title>", "</title>"), "", $hasil[0]); } $validateurl = $link; $regex_pattern = "/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/"; $match; if(!preg_match($regex_pattern, $validateurl, $match)){ $band = "Not A Youtube Request"; }else{ $band = $title;; }
  4. @requinix Thank you for that. I tried the following but with no luck, based on what you said. Admittingly, I have to come to best guess solution for it because regex is the bane of my brain haha $regex_pattern = "/(youtube.com/shorts|youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/"; $regex_pattern = "/youtube.com/shorts/(\w+)|youtube.com/watch\?v=(\w+)|youtu.be/(\S+)?/"; $regex_pattern = "/youtube.com/shorts/(\w+)|youtube.com/watch\?v=(\w+)|youtu.be/?si=(\w+)/"; $regex_pattern = "/youtube.com/shorts/(\w+)|youtube.com/watch\?v=(\w+)|youtu.be/?(\S+)/"; I should also note that the following is my original one that works for all but the shorts but I tried to use it with variations of what you said and no luck... $regex_pattern = "/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/"; Edit: No, I don't want to use javascript. I just added that in the original post because others I have asked keep telling me to use javascript instead haha
  5. Hello. I have the following code that works for it's intended purpose for all youtube links including shares (si) extensions. Can someone please tell me how to alter it to add the shorts? This is in PHP and has to remain that way. I can't use javascript for this because this is part of a very long php coded page. Shorts example https://www.youtube.com/shorts/J0iIQ629N2c My code that works for all but shorts $regex_pattern = "/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/"; I have tried the following and it failed. I should note that I have been trying to understand regex patterns and my mind doesn't seem to want to learn it at a normal good rate but I keep trying $regex_pattern = "/(youtube.com|youtu.be)\/(shorts|watch)?(\?v=)?(\S+)?/"; $regex_pattern = "/(youtube.com|youtu.be)\/(shorts)\/(watch)?(\?v=)?(\S+)?/"; $regex_pattern = "/(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?(\shorts)?/";
  6. @Barand Thank you I will try to put that in with what @mac_gyver gave too. I've been studying this a lot over the last couple days and I'm starting to understand how it all works. I'm still stuck on how to keep a new question from showing (or the current question) below the results (after the user answers it). I unset it all to get it to do a new one in case of refresh so that works but even before I did that then it would still show that question again below the results. The problem with that is that it will allow the user to answer again if they get it wrong. If they get it wrong then there's no redo, I don't want them to have the ability to put in a new answer to move forward.
  7. @mac_gyver I resolved the division zero issue by changing the lines rand(0, 9) to rand(1, 9) If you don't mind an extenstion on it, is there a way to not show the question and answer form after the answer is given? Right now, it shows the answer again under the CORRECT or INCORRECT display, after the answer is given.
  8. @mac_gyver To answer your question, the goal was for learning and also give my viewers a simple math question that will go along with a bunch of other trivia. Just for fun. And yes also to learn from. I'm told by most people that I know that my mind works weird. I tend to reverse engineer things to learn most. I'll take a web page and see it as a viewer to see what it does, then look at the script to see how it works, then learn and build from there. Most of the time it works for me, but then other times it doesn't. Unfortunately I have a learning handicap to where if I was to be given instructions on how to build a clock (like a literal one that is on the wall) I would be lost. But if I took a clock apart, then I can see how it's done and build another one. And then often enough I can build more to add to that clock from there. I know... I'm strange. That being said, what you posted is VERY educational to me! I simply pasted your code that you provided into a page and then uploaded it. I saw it working. Then I went back to go line by line from what you said before providing the code and learned from it while going through that code. And now it all MOSTLY makes sense to me. I confess that not all of it does but I know it will soon, as some of it is just termonology that I'm unfamiliar with. HOWEVER, it has some terms that I didn't understand 2 or 3 months ago, but now do because of this website. Overall, I understand a lot more of why it works as apposed to what I had created to begin with. Sorry this is a long post but I wanted to properly thank you by explaining exactly how it educated me. I am very greatful for that! THANK YOU!
  9. I hope I'm not stepping out of bounds on this, but is there a way I can just pay someone to make this work? If I'm out of line then I appologize. Another 5 hours have passed and I can't make heads or tails out of how to make this work. I don't need to save the answer in a database or anything like that. It's just going to be as basic as can be. A random math question shows, the user enters the answer, then it shows if it's right or wrong without showing a new math question. I feel foolish I can't find a single thing online to where I can learn what to do here. And I'm sure you both are correct in what you're saying. Unfortunately, I don't understand what you're saying
  10. @mac_gyver and @Barand thank you for that info! I appreciate it. I think I understand what you're saying. But then again not really haha. If I'm understanding you, then it's not really working to post anything but is just recycling the page to make a new math problem? But then, it's not? Just translating in my own mind that is less skilled with less termonology haha. Okay so, is what I'm attempting to accomplish even possible then to do all in one page? The only session that I have with it is the users session (different php script that is going to be included once I get this working so I can add some database scores and etc etc)
  11. Hello everyone. I hope you're having a great day! I'm attempting to make a basic math test that gives one question, a input field to enter an answer, and if its correct then it shows the answer and an image to say they win. If in correct then still shows the answer with an image that says they didn't win. Sounds pretty basic right? I can't wrap my head around what I'm doing wrong. When I run this, then weather it's right or wrong, I just get a blank page. I've been at this for so long with different variations that I'm starting to feel fatigue haha. Any help is greatly appreciated. The file is math8.php PS I also get the follow errors which is confusing me because in my mind, these ARE defined. But I can see that the errors say their not. I'm not understanding why though. Warning: Undefined array key "number_entered" in math8.php on line 32 Warning: Undefined array key "submit" in math8.php on line 34 <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $rand1 = rand(0, 9); $rand2 = rand(0, 9); $operator = array('*', '/', '+', '-'); $randoperator = $operator[rand(0, 3)]; switch ($randoperator) { case "+": $finaalvalue = $rand1 + $rand2; break; case "-": $finaalvalue = $rand1 - $rand2; break; case "*": $finaalvalue = $rand1 * $rand2; break; case "/": $finaalvalue = $rand1 / $rand2; break; echo $rand1 . $randoperator . $rand2 . '=' . $finaalvalue; } ; if(!isset($_POST['number_entered'])){ $number= $_POST['number_entered']; $submitbutton= $_POST['submit']; echo ' <form id="id" action="" method="POST"> <br><b>Level 1<br>Do The Math</b><br><br>'; echo $rand1 . $randoperator . $rand2 . '='; echo '<input type="text" name="number_entered" value="" autocomplete="off"> <br><br>'; echo ' <input class="button" type="submit" name="submit" value="Enter Guess"><br><br> </form> '; if ($submitbutton){ if ($number != $finaalvalue){ echo "Incorrect guess<br>The correct<br>number was <b>$finaalvalue</b> <br><img src='sorry-tryagain.png'><br>"; }else{ echo "<img src='you-win.png'><br><b>$finaalvalue</b> IS THE<br>CORRECT GUESS!</b><br>"; } } } ?>
  12. Update... For anyone that comes here to find an answer, I was making some coffee and it hit me... I should define the first part, then make it a full url to strip the video id, and THEN put it in the rest to get the title. And after about 20 min of mangling it, this is the solution that works $ytvideo1 = $link; $linkurl = "$ytvideo1"; parse_str( parse_url( $linkurl, PHP_URL_QUERY ), $vid ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $linkurl, $match); $youtube_id = $match[1]; $preurl = "https://www.youtube.com/watch?v=$match[1]"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $preurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $document = htmlspecialchars($output); curl_close($ch); $line = explode("\n", $document); $judul = ""; foreach($line as $strline){ preg_match('/\&lt;title\&gt;(.*?)\&lt;\/title\&gt;/s', $strline, $hasil); if (!isset($hasil[0]) || $hasil[0] == "") continue; $title = str_replace(array("&lt;title&gt;", "&lt;/title&gt;"), "", $hasil[0]); } echo $title; ////// This shows the title of the video from any youtube link
  13. I saw those pages. Good tools I'm sure to use. I was hoping to try to make this work as I'm working on it though. Mainly because if I use their api and then run into this later for something else that needs regex, and there is no api for it (other than youtube for example) then I will be back to this step trying to make it work again. Most of what I do (this is mostly as a hobby, sometimes as a favor for friends) is to build, then learn from it. Even when I get clips of code from other sites, I'll often be able to see why it works, once it finally does work. Not so much the case with redex though. It's really tough to transate for me
  14. That would be a doable except unfortunately all of that string of things looks like a plate of spaghetti trying to be alphabet soup haha. I can't translate it enough to know how to add the "title" part to a different one, or how to make the current one for the title work with youtu.be Also, there's the other issue when the "?si=" is added from the token shared link. I managed to make it all work for the thumbnail, but not the title. And honestly, that was done by stumbling upon the code on other sites. I continue to look into the regex101 and other sites but my brain doesn't want to translate how to break apart all that string of stuff to understand it, to build onto it.
  15. I'm attempting another go at this regex world and I feel like I'm reading something from mars. So I have 2 different codes that work for 2 different things. I'm hoping I can get some help with merging them. I stared at the regex101 for a few days now and I'm not getting it. Note: I didn't include any database stuff or connections and etc. I don't think it's relevant because the link is being sent just fine. I can't get it to convert. Objecting: To sort of "Smush" the two regex together to be able to get the title from any youtube link type. This one works for getting the title of a youtube video, if the video link is (for example) https://www.youtube.com/watch?v=HQBG42Ggtac However it will NOT work with videos withe a link like https://youtu.be/HQBG42Ggtac?si=l2EE-4vqC9U5xIkj <?php $link = $_POST['link']; ////// coming in from a form on a webpage as the user enters a youtube link $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $document = htmlspecialchars($output); curl_close($ch); $line = explode("\n", $document); $judul = ""; foreach($line as $strline){ preg_match('/\&lt;title\&gt;(.*?)\&lt;\/title\&gt;/s', $strline, $hasil); if (!isset($hasil[0]) || $hasil[0] == "") continue; $title = str_replace(array("&lt;title&gt;", "&lt;/title&gt;"), "", $hasil[0]); echo $title; ////// prints the video title on the screen ?> HOWEVER... The following will work when getting ALL links for getting the video thumbnail $link1 = $_POST['link']; ////// sent from a form on a different page $ytvideo1 = $row['link']; $url = "$ytvideo1"; parse_str( parse_url( $url, PHP_URL_QUERY ), $vid ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); $youtube_id = $match[1]; echo "<img src='http://i4.ytimg.com/vi/$match[1]/mqdefault.jpg'>"; ////// shows the video thumbnail Any guidance is massive appreciated. My few remaining hairs will thank you too as I wont pull the rest of them out trying to get this to work haha.
  16. Update. Here is the working final if anyone else comes here looking for a solution. I credit @Barand for getting me there! ❤️ $sql = "SELECT SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) >= 6) as expired , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) >= 3 and timestampdiff(MONTH, created_at, now()) < 6)as warning , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) < 3) as pending , SUM(visited IS NOT NULL) as ok, visited, created_at FROM users ORDER BY visited DESC";
  17. Hello again. I went with this one after adding a few other lines after it to print it out correctly and this works. However I changed it to the following and it's echo $sql = "SELECT SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) >= 6) as expired // after 6 months it is expired , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) > 3 < 6) as warning // between 3 and 6 months it is in warning , SUM(visited IS NULL AND timestampdiff(MONTH, created_at, now()) < 3) as pending // after 3 months it is pending , SUM(visited IS NOT NULL) as ok, visited, created_at FROM users ORDER BY visited DESC"; $query_result = $conn->query($sql); while ($row = $query_result->fetch_assoc()) { $visited = $row['visited'] ; $created_at = $row['created_at'] ; } $result = $conn->query($sql); if(!$result) { die('Error: ' . mysqli_error($link)); } else { $num_rows = mysqli_fetch_assoc($result); // echo it echo "<font color='black'>Expired</font>: <font color='red'>" . $num_rows['expired']."</font>"; echo "<br>"; echo "<font color='black'>Warning</font>: <font color='red'>" . $num_rows['warning']."</font>"; echo "<br>"; echo "<font color='black'>Pending</font>: <font color='red'>" . $num_rows['pending']."</font>"; echo "<br>"; echo "<font color='black'>Okay</font>: <font color='red'>" . $num_rows['ok']."</font><br><br>"; } I know my font tags aren't exactly ideal. I get told that a lot. But since they still work and it's what I'm used to, I don't put it as top priority to change yet lol THE PROBLEM is this is what it prints Expired: 186 Warning: 321 Pending: 44 Okay: 28 And there are only 349 records. So I'm assuming something is wrong with the Expired and Warning because the Okay and Pending are accurate Here's something I didn't explain before and I should have... and I apologize for that. So a lot of those accounts don't have ANY login entry at all, and it is blank in the "visited" row What I am attempting to do is * if the user has logged in (visited has a timestamp), and is less than 3 months since they logged in, then it's in Okay * if the user made the account, and hasn't logged in since they created it (visited column is still blank) in less than 3 months, then it's in Pending * if the user has logged in (visited has a timestamp), and hasn't logged in more than 3 months but less than 6 months, then it's in Warning * if the user made the account, and hasn't logged in since they created it (visited column is still blank) in more than 3 months but less than 6 months, then it's in Warning * if the user has logged in (visited has a timestamp), and hasn't logged in more than 6 months, then it's in Expired * if the user made the account, and hasn't logged in since they last logged (visited column is still blank) in more than 6 months, then it's in Expired Somehow, what you provided ALMOST works. But that Expired and Warning is off some how. Any thoughts? Side note: I didn't attempt your last suggestion because (thought I could be wrong) it looks like I would have to alter the database and I'm not allowed to do that. But good educational suggestion still
  18. @Barand You're awesome thank you. I can't wait to test all of that out tomorrow
  19. Thank you I will certainly give that a shot tomorrow when I get back to the computer. Just for educational purposes though, is it not possible to stem from what I had and add to it? Like for example if ($diffdate->m >= 3 OR $diffdate->y >= 1) { $total1 = (something here that counts the above if statment for a total with that condition); } echo $total1; If not, I'd be curious to know why? Many thanks!
  20. Yes each time they login, a new date enters in "visited"
  21. $sql = "SELECT id,unique_id,fname,date_format(visited, '%b %e %Y %h:%i%p'),date_format(created_at, '%b %e %Y %h:%i%p'),visited,created_at FROM users ORDER BY visited DESC"; This is important to have as a ORDER BY because the list as a whole starts with users most recent logged in to last
  22. The database table has colums "created_at" and "Visited" The code above shows each one correctly as exired = hasn't logged in at all since they created the account and it's been over a year and 3 months pending = hasn't logged in at all since they created the account and it's been within 3 months since created okay = has logged in within 3 months since last login Created_at = created account Logged in = visited So I want to use that information to count (the code in the original post shows each one) how many are Expired how many are Pending and now many are Okay
  23. Hello. I have a few pages that count total entries in a db that work fine. And I have some that count entries WHERE just fine. But what I'm not able to figure out is how to echo a count based on a few variables that are stated after the initial SQL statement. I want to be able to have (for example) echo = 'Okay = 10, Pending = 5, Expired = 2'; and it based on if ($diffdate->m >= 3 OR $diffdate->y >= 1) { $expire = "EXPIRED"; } elseif (empty($visited)) { $expire = "PENDING"; } else { $expire = "OKAY"; } Any thoughts?
×
×
  • 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.