So for my Garry's Mod server, I have a loading screen using my website. I only have an image currently, but I wan't to make it play a song while the user waits while loading. My plan is that I make a list of YouTube links, and the PHP coding picks a random link, and plays that song. I have no clue on how to use PHP except for variables.
As per your question, I suggest to you one example. So, Try the code,
Youtube URL look like this : http://www.youtube.com/watch?v=yWsqTrDJ_gU
The part you're going to want to copy is everything after the equals sign, or in the example above: yWsqTrDJ_gU
Copy on that text into a text file, hit Enter and paste everything after the equals sign of the URL on the next video page on the following line. You'll end up with a series of lines that look something like this:
5MQ0QX870FE
yWsqTrDJ_gU
JyTawuNvQi0
HwRQ9dbti-4
_ziv_WeBLvo
Save this text file with a meaningful name and upload it to your Web server. Next you need to build the code to display your video. If you copy the following and paste it onto a page that supports PHP, replacing only the YourVideoList.txt with the path to your file, you should get a YouTube player with a randomized set of videos.
<?php
// Build an array from the list of YouTube videos
// Replace YourVideoList.txt with the path to your text file
// This will likely be something like /home/accountname/public_html/foldername/etc
$video_array = file('YourVideoList.txt');
// Randomly pick one video from the array
$video = $video_array[rand(0, count($video_array) - 1)];
$video = trim($video);
?>
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/<?php echo $video;? >"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/<?php echo $video;?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
Note: Don't copy anything beyond this point for your code.
Hope! it's work for you!!
Related
I've looked all over the place and cant seem to find how to do str_replace but search the whole document instead of just a string.
For example, by using string replace, I can check a string, look for certain text, and replace that text with something else.
I want to look in the whole page (The whole index.php page). Look for certain text, and replace that text with new text.
I can accomplish this with jquery, the only problem is that it is done after the page loads so its loading double the information. I need it done before the page loads. Or maybe there is another way to change the text with javascript before the page even loads. But figure PHP would be best for this. Any suggestions?
--UPDATE ONE--
I'm using the easyazon plugin to load in products from amazon. Here is the specific code that pull in the image from amazon into my index page.
<?php if($image_atts) { ?>
<div class="easyazon-block-image-container">
<?php printf('<a %s><img %s /></a>', easyazon_collapse_attributes($link_atts), easyazon_collapse_attributes($image_atts)); ?>
</div>
<?php } ?>
Under the $image_atts array, the code there is>
if(isset($item['images']) && is_array($item['images'])) {
$image_index = 3;
while($image_index >= 0) {
if(isset($item['images'][$image_index])) {
$image_atts = array(
'alt' => $item['title'] ? $item['title'] : '',
'class' => 'easyazon-block-information-image',
'height' => $item['images'][$image_index]['height'],
'src' => $item['images'][$image_index]['url'],
'width' => $item['images'][$image_index]['width'],
);
break;
}
$image_index--;
}
} else {
$image_atts = false;
}
When looking at the source of the index.php after its generated. The image tag looks something like this.
<div class="easyazon-block-image-container">
<img class="xxx" src="https://xxxx.amazon.com/xxxx/xxx/xxx/xxxxx120.jpg">
</div>
Here is where lies my issue. If you look at the src part of the image tag, it pulls a small image down from amazon at 120px width as shown by the end of the filename.
What I need is to pull down a larger width image from amazon by changing the 120 to a 300.
https://xxxx.amazon.com/xxxx/xxx/xxx/xxxxx300.jpg
Which in turn pulls down the image at 300px wide.
I tried doing this in jquery, to search for the string "120" and replace it with "300". This worked successfully but in turn becuase it happened after the browser loaded, it caused the browser the download 2 different images. One at 120px and one at 300px. So that is definitely a no go. For every image on the page it would download both versions of the image.
What i need to do is look for the string 120, in the easyazon-block-image-container, and then change it to 300, BEFORE it is sent to the browser. I hope this helped in giving a little more of the code.
I don't want to give to much code on the plugin for the developers privacy. But for my own defense, I looked all over the plugin and cant find anywhere where the plugin is telling itself to download the 120px version of the image. If that was the case I could have just changed it to 300 in the code. Any help would be appreciated. One of the last thing keeping me from going live with my site :(
A string can be as short or long as you want, str_replace()should work fine.
See: http://php.net/manual/en/function.str-replace.php
i'm using shadowbox for my website to open the big images with clicking thumbnails as you know. My Problem is, i'm fetching the users' facebook profile photo like :
$large = "https://graph.facebook.com/{$id2}/picture?type=large";
$small = "https://graph.facebook.com/{$id2}/picture?type=square";
And it's working perfect, but in shadowbox i have problem with large image..
I'm calling this in shadowbox like :
<a href="<?php echo $large; ?>" rel="shadowbox">
<img style="max-width:50px; max-height:50p;" src="<?php echo $small; ?>" />
</a>
As you can imagine, small image is showing perfect, but when i click on the small image which has href, it fails to show the large image.
I've tried to change large image variable to this :
$large = "https://graph.facebook.com/{$id2}/picture?type=large&redirect=false";
but also it has failed to show the large image..
Hope you can help, thank you
I haven't worked with Shadowbox before, so I don't know how it works behind the scenes. It may be that it can't deal with a url that returns another url for the large image.
Try making the API call with php and then passing this result to shadowbox.
$large = file_get_contents("https://graph.facebook.com/{$id2}/picture?type=large&redirect=false");
Of course, using file_get_contents() like this is a quick and dirty method. If it works, before you roll this out to a production site, you'll want to use cURL or better yet the Facebook PHP SDK to do this.
Assuming you're using shadowbox to show multiple users' photos on a page, you'll probably end up bumping into the API limits at some point. To prevent this, redo your API calls to grab multiple photos in one shot:
$large_photos = $fb->api('/picture?type=large&redirect=false&ids=' .
implode($ids_array, ','));
https://graph.facebook.com/{$id2}/picture?type=large&redirect=false basically returns you a text content the URL of the image. That's why it's not showing.
Eg.
https://graph.facebook.com/yungsenriady.budiman.3/picture?type=large&redirect=false
returns
"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/157348_100001167523294_1569184886_n.jpg"
Try just use
https://graph.facebook.com/{$id2}/picture?type=large
Right now I have a variable: $blogbody which contains the entire contents of a blog.
I'm using the following to convert URLS to clickable links:
$blogbody = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","\\0", $blogbody);
And the following to resize embedded video:
$blogbody = preg_replace('/(width)=("[^"]*")/i', 'width="495"', $blogbody);
The problem I'm running into is the embedded video not working, comes back with an Access Forbidden error (403). If I remove the line to convert URLS to links, the embedded video works fine. Not sure how to get these two working together. If anyone else has a better solution to converting URLS to clickable links and resizing embedded video let me know!
This might be happening because the link which you use to embed the video also gets his <a href=''> tags added. So instead of just converting all links, check that they don't have ' or " directly behind or in front of them - this will make sure that the embedded videos' links won't get anchor tags.
I am trying to do the following; dynamically pick a server with the image on it, and then show said image in img src="". Yeah I know, I am horrible at explaining stuff like this but this should clear it up:
dl-main.php (on server0.domain.com)
$url = 'http://server2.domain.com/offerimage.php?f='.$_GET["f"];
header( 'Location: '.$url ) ;
offerimage.php (on server2.domain.com)
//Lots of link-protection stuff here
$f = "/".$_GET["f"];
$url = 'http://server2.domain.com'.$uri_prefix.$m.'/'.$t_hex.$f;
echo' <img src="'.$url.'"></img> ';
dl.php (on many other servers)
img src="http://server0.domain.com/dl-main.php?f=lalala.gif"
So it pretty much goes like this: Random person adds img src directing to dl-main.php?f=filename on server0. server0 then decides which server will provide the image. In the above example I am using only one server; server2
Now I simply want dl.php to show the photo hosted on server2.domain.com .
As it stands when I directly visit dl-main.php it succesfully redirects me to dl.php, which then succesfully shows me the image I requested. But when I use dl-main.php in a img src it doesn't show the image. I didn't expect it to work but it was worth a shot, but now I don't know what to do anymore :o
I hope this failed attempt is a good example of what I'm trying to accomplish here.
Thanks!
Here's the problem. You call image from server0 using:
<img src="http://server0.whatever/dl-main.php?f=thatimage.something" />
Where the dl-main.php code redirects to server2. Here, you do:
echo' <img src="'.$url.'"></img> ';
So basically the original img tag would get another img tag instead of the image data. That's why the browser can't render the image. You should echo the content of the image instead of an img tag.
Try using your browser's developer tools and check the request to server2 to verify my guess.
It can't work, your second script (offerimage) is producing text/plain, you should produce image/...in order to use img
I have some thumbnail images with its larger version.I placed the thumbnail images in a page.Now for link I just gave a link
<img src="thumbnail1.jpg>
but for this I have to make different pages for showing larger one.I want to give a link to show them in a single page.means whenever I will click the thumbnail it will open the larger one in a page with the same url but with its name like
imagegallery.php?news=images/largerimage1/13.jpg
imagegallery.php?news=images/largerimage1/14.jpg
so how to do that?
Pretty basic stuff, I suggest you get to read some PHP tutorials on the internet to get some knowledge on one thing and another.
The ?news= part in your URL is a parameter that can be read by PHP. This type is known as $_GET. To get this part you would need $_GET['news'] so if we'd use your first link and place this inside a script: echo $_GET['news']; the page would say images/largerimages1/13.jpg.
In order to get the image loaded on your website we need some simple steps, I'm changing the news parameter into image, that suits better for your script since it ain't news items:
<?php
// Define the path (used to see if an image exists)
$path = 'your/absolute/path/to/public_html/'; # or wwwroot or www folder
// First check if the parameter is not empty
if($_GET['image'] != "") {
// Then check if the file is valid
if(file_exists($path . $_GET['image'])) {
// If an image exists then display image
echo '<img src="'. $_GET['image'] . '" />;
}
}
?>
Below this script you can put all your thumbnails the way you want. Ofcourse, also for these thumbnails there are some automated options. But I strongly suggest you get a good look at the script above and some beginner PHP tutorials so you completely understand the example given. This still isn't the best method, but it's kicking you in the right direction.
if your imagegallery.php is in root of your domain, you can just add slash as a first char to links like this:
<img src="thumbnail1.jpg>
else you will have to write some php function which it returns BaseUrl of your web. Then it should looks like this:
<img src="thumbnail1.jpg>
maybe you can something like this,
Techincally, there is no thumbnail image, just a stretch version of the regular image
I don't understand which part you don't know how to do:
- the link part?
it should look like
<img src="thumbnail1.jpg>
- or the PHP part (the file called imagegallery.php)?