How can I grep YouTube video ID from the web? - php

I was wondering if it was possible to get all the video IDs from a YouTube playlist pages and display them in a list.
<li class="playlist-video-item odd">
<a href="/watch?v=oHg5SJYRHA0&list=FLk8PLezsTU6MuuBxE5utNQw&index=3" class="tile-link-block video-tile">
<span class="video-index">3</span>
<span class="playlist-video-item-base-content">
<span class="thumb-container">
<span class="ux-thumb-wrap">
<span class="video-thumb ux-thumb-114 "><span class="clip"><img src="//i2.ytimg.com/vi/eVMWgmQA4Ig/default.jpg" alt="Thumbnail" ></span></span>
<span class="video-time">3:37</span>
<button type="button" class="addto-container addto-button short video-actions yt-uix-button yt-uix-button-short" onclick=";return false;" data-button-menu-id="shared-addto-menu" data-video-ids="oHg5SJYRHA0" data-button-action="yt.www.addtomenu.load" data-feature="thumbnail" role="button"><img class="yt-uix-button-icon yt-uix-button-icon-addto" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""><span class="yt-uix-button-content"><span class="addto-label hid">Add to</span></span><img class="yt-uix-button-arrow" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""></button>
</span>
As you can see the ID is here data-video-ids="oHg5SJYRHA0"

Rather than scraping the IDs from markup like that, you should probably take a look at the YouTube API

I guess you want this to be done with jQuery, according to your tags.
$('span.ux-thumb-wrap button').data('video-ids')
Your example code only have one ID, so I wouldn't know how to create a list. Or what type of list for that matter. Please add a comment with further instrux as needed.

Related

(PHP) Trying to controll the include function

I am now done making my website dynamic (control multiple pages througe 1 page)
I have template where I have 2 side bars left and right, right for categories, left for the the many pages of each category.
Now using the include function to dynamicly generate the side bars is great,
but i am also using class:current on these side bars so the user can easily detect where he is.
now with the right sidebar there is no problem because if the user is in HTML category it will be highlighted with class:current but will not need to change, because user is still in HTML category.
but if the user switch page the left side bar will stay with the last class:current (for example html intro ), even tho user switched to next page (html basics).
i can only have 1 class:current when using the include function.
how can i controll that?
the code below is the file that im including to each page dynamicly it is .php file.
<div class="sidenav">
<h3> HTML Collection</h3>
<hr class="hr1">
<a class="current" style="cursor: pointer;" onclick="window.location.href = 'html_default.php';"> HTML Intro</a>
<a style="cursor: pointer;" onclick="window.location.href = 'html_editors.php';"> HTML Editors</a>
<a style="cursor: pointer;" onclick="window.location.href = 'html_basics.php';"> HTML Basics</a>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<div class="sidenavright">
<h3> Categories</h3>
<hr class="hr1">
<a style="cursor: pointer;" onclick="window.location.href = '../javascript/js_intro.php';"> Javascript</a>
<hr class="hr1" />
<a class="current" style="cursor: pointer;" onclick="window.location.href = '../html/html_default.php';"> HTML</a>
<hr class="hr1" />
<a style="cursor: pointer;" onclick="window.location.href = '../howtomain/howto_default.php';"> HowTo</a>
<hr class="hr1" />
<a style="cursor: pointer;" onclick="window.location.href = '../python/python_intro.php';"> Python</a>
<hr class="hr1" />
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
You should be doing this all though JavaScript really, something like AngularJS, or maybe even use Laravel and it would be very easy to control it in your blade views.
Here’s something you can do however.
From the file where you are including it, define a variable before the include that will allow the include to know what page you’re on.
Like so:
$currPage = “page1”;
Then in your include, on each tag, you can programmatically put your current class on using one line if/elses, like so:
<a <?php ($currPage == “page1”) ? echo ‘class=“current”’ : echo ‘’?>>Page 1</a>
And repeat for all pages you want.
One line if/elses in PHP go like this:
Condition ? //true : //false
Good luck

PHP echo printing outside of my html bounds

I'm making a website where users can post stories etc and they get put into the MySQL database and the front page pulls the top-rated stories from the database and fills in the HTML template I made to display.
So I pull the top rated post and put it inside the article tags that I've made inside my HTML. The question is when it displays it displays outside of the box. Like so
The actual display is supposed to look like this
How do I format the PHP code, Or is there some better way to go about doing this?
<article class="post featured">
<header class="major">
<span class="date">April 25, 2017</span>
<h2>
And this is a<br />massive headline
</h2>
<?php echo '<p>' . htmlspecialchars($row['post'], ENT_QUOTES, 'UTF-8') . '</p>'; ?>
</header>
<img src="images/pic01.jpg" alt="" />
<ul class="actions special">
<li>Full Story</li>
</ul>
<span class="tags badge-pill badge-primary">Otero</span>
<span class="tags badge-pill badge-info">SCR</span>
<span class="tags badge-pill badge-success">Class of '22'</span>
<span class="tags badge-pill badge-danger">Male</span>
</article>
EDIT: Here is the HTML spot I'm talking about
Ok, It`s easy to solve. First your string has only one word (because doesn´t have spaces) an second, when you have a paragraph, the tag that wrap content has an autoalignement.
Maybe you can try adding some css rules for your parent div?
You may check this : https://stackoverflow.com/a/3367759/8186765

PHP: index.php posts headers are not clickable, not able to click inside post through header

Good evening my fellow coders, I came here with a quest to find an answer for my whole day solution looking problem.
Why this code
<h1><?=$post["post_subject"]?></h1>
is not making my post headings link-able (aka if you click on the title, it should redirect inside of the post).
I did made function in post.php, where
function view(){
$this->post = get_first("SELECT * FROM post NATURAL JOIN user WHERE post_id='$post_id'");
}
My github for the project is Here
Thank you for your time reading this :)) I can't find the solution on my own anymore, I hope you php gods now better than me.
Update.
It was not unclear. I asked simply fair question. Why is H1 not making post TITLE clickable, where there is a href= inside.
<div class="span8">
<h1><?=$post["post_subject"]?></h1>
<p><?=$post["post_text"]?></p>
<div>
<span class="badge badge-success"><?=$post["post_created"]?></span><div class="pull-right"><span class="label">alice</span> <span class="label">story</span> <span class="label">blog</span> <span class="label">personal</span></div>
</div>
</div>
All I did was made a copy of post_index.php into posts_view.php that allows me to click on title and see the post inside.
<?foreach( $posts as $post ):?>
<div class="span8">
<h1><?=$post["post_subject"]?></h1>
<p><?=$post["post_text"]?></p>
<div>
<span class="badge badge-success"><?=$post["post_created"]?></span><div class="pull-right"><span class="label">alice</span> <span class="label">story</span> <span class="label">blog</span> <span class="label">personal</span></div>
</div>
</div>
after
<div class="span8">
<h1><?=$post["post_subject"]?></h1>
<p><?=$post["post_text"]?></p>
<div>
<span class="badge badge-success"><?=$post["post_created"]?></span><div class="pull-right"><span class="label">alice</span> <span class="label">story</span> <span class="label">blog</span> <span class="label">personal</span></div>
</div>
</div>
I changed <h1><?=$post["post_subject"]?></h1> to <h1><?=$post["post_subject"]?></h1> but there is a problem, it doesnt make the h1 clickable, but I have a href.
Yes. I found my own solution for my own question.
In fact. I had to put<h1><?=$post["post_subject"]?></h1> into post_index.php not post_view.php.

Share the picture directly to facebook using sharethis plugin

I am using ShareThis plugin and it's working perfectly. But I am building a website something close to Facebook , and it contains images.
When I share using ShareThis plugin it shares the link to the original page. But what I want is to share the picture itself directly to Facebook (like what Instagram does with Facebook).
So is there any way to do it? I am using PHP and HTML
<div class="sharePopup" id="shareD">
<div class="iner">
<span class='st_sharethis' displayText=''></span>
<span class='st_facebook' displayText=''></span>
<span class='st_twitter' displayText=''></span>
<span class='st_linkedin' displayText=''></span>
<span class='st_pinterest' displayText=''></span>
</div>
</div>
<a href="#" class="facebook social-provider-icon"
onclick="
window.open('http://www.facebook.com/sharer/sharer.php?s=100&p[url]=' + encodeURIComponent(location.href) + '&p[images][0]=<?php echo $imageforfb; ?>&p[title]=<?php echo $ftitle; ?>',
'facebook-share-dialog',
'width=626,
height=436');
return false;">
</a>

PHP Fancybox same ID

This may seem like a weird request, but this is something I have to use based on something I have been provided that is live.
I have a voting system that uses an id for the voting button based on the entry id, so the code looks like:
<div class="like_wrap">
<div class="vot_plus" id="vt_img41"></div>
</div><!--like_wrap-->
This works how I need it to, however when you click the image within the vote it opens up a larger picture of the entry (again this works), but the client would like to add that vote to the fancybox popup. However when this is added it removes all references as it is calling the same ID twice. Any idea how I can get the voting button to appear on both, but actually look like it only appears once?
Here is the full code of an entry:
<div class="single ">
<a href='#inline41' rel='example_group' title='NAME GOES HERE'><img src='IMAGE GOES HERE' height='90' width='90' class='image' /></a>
<div class="right_col">
<h3>NAME GOES HERE</h3>
<div class="like_wrap"><div class="vot_plus" id="vt_img41"></div></div><!--like_wrap-->
</div><!--right_col-->
<div class="clear"></div><!--clear-->
<div id="inline41" style="display: none;">
<img src='IMAGE GOES HERE' height='400' class='image' /></a>
<div class="vote_bottom">
<p>Vote: </p>
<div class="like_wrap"><div class="vot_plus" id="vt_img41"></div></div><!--like_wrap-->
<div class="clear"></div><!--clear-->
</div><!--vote_bottom-->
</div>
</div><!--single-->
Any ideas how I can do this?
Thanks.

Categories