I wrote a short PHP script to scrape the images from the homepage of http://www.imgur.com. Here is the code:
$imgur = file_get_html('http://www.imgur.com');
foreach($imgur->find('div[class="post"]') as $images)
echo "<span id=\"images\">$images</span>";
The problem is that after scraping the divs with class=post, the pictures link to the gallery for the image, but the "a href=" looks like /gallery/48ZPT instead of http://www.imgur.com/gallery/48ZPT.
So when I click the link where the images are on my website it takes me to mysite.com/gallery/48ZPT but that directory doesn't exist so I get an error.
Is there anyway to add "http://www.imgur.com" to each variable href as it is pulled from the site?
I know this might be a little confusing, but I would appreciate any help.
$imgur = file_get_html('http://www.imgur.com');
foreach($imgur->find('div[class="post"]') as $images)
{
echo "<span id=\"images\">"."http://www.imgur.com"."$images</span>";
}
Related
I have PHP code that generates HTML code which makes a grid of images. The images are taken from links that are generated for each new image, I also add 133x100 at the end of the image link to resize it on the page. My problem is that a seemingly random selection of images won't display, and I just get a broken image symbol. For example:
This is a link to an image that is generated on my page and is displayed.
This is a link to an image that will not be displayed.
I am only allowed to post 2 links, but removing the %20.%20/133x100 from the end of the last link will show what the picture should be.
Here is the part of the code for the image source:
function display_images(){
//This cycles through each image and displays it as HTML
while($row = $item->fetch()){
Echo "`<img src= '$link[Image_Link] . /133x100' />`"
}
}
It is then called here in a class which puts the images in a grid:
<ul class="rig columns-4">
<?php
display_images();
?>
</ul>
Seemingly about every 2/20 images won't work, and seeing all the links are in the same format, I don't understand why they won't work, and it just seems random.
EDIT: I have noticed that the links that work have 62fx62f at the end of them before the added %20.%20/133x100. If I add it to the raw link in the right place, it makes the image work. But using that generated link, the image still won't load on the page. So using a link with a working image will not work on the page. (This is the same with the raw link without %20.%20/133x100, that links to an image but also won't work on the website)
When visiting the links, the urls look like this:
http://www.example.com/image/randomcharacters%20.%20/133x100
The links work without the %20.%20 at the right dimensions, like so:
http://www.example.com/image/randomcharacters/133x100
This leads me to believe that it may work if you try using the following for the image source instead:
<img src= '$link[Image_Link]/133x100' />
The full code would look like this, for the while function:
while($row = $item->fetch()){
echo "<img src= '" . $link['Image_Link'] . "/133x100' />";
}
I am not aware of steamcommunity much but from the looks of it, i think you should try this.
Instead of putting
. /133x100
Use
/133fx100f
So your URLs would be
while($row = $item->fetch()){
echo "<img src= '" . $link['Image_Link'] . "/133fx100f' />";
}
Just did some trial and error and found out. No explanations for this though!!
I am working on a website that i just uploaded to a test area.
http://cascarinosonline.com.216-70-85-163.messtudios.com/
I want to edit the gallery based on an incoming link. Currently I am using supersized jquery pluggin for the gallery.
When you view the gallery now its working as it should, however when you are on the Homepage and you click on "new outside area" on the bottom right corner I want it the link to take you to the gallery page but start on a different slide.
I couldn't find an easy way to do this with supersized jquery plugin... I thought it would be a simple URL anchor tag like so:
http://cascarinosonline.com.216-70-85-163.messtudios.com/gallery.php#slide12
So I think this is my solution, the default gallery page is labeled with a php value:
<?php $page = "gallery" ; ?>
And in my code it says
<?php if ($page == "gallery" ) { echo $galleryAll; } ?>
$galleryAll; has the list of gallery images in the normal order.....
Now, I made a different php code that is:
<?php if ($page == "galleryfix" ) { echo $galleryOutside; } ?>
Now this $galleryOutside; has the outside image first in the list.
Both examples above work, if I manually change the php page value to equal the content I want.
My Questions is:
I added an anchor tag to the homepage link and it looks like this:
http://cascarinosonline.com.216-70-85-163.messtudios.com/gallery.php#outside
I want php to find the url and if it has "#outside" then echo $page == "galleryOutside" else $page == "gallery"
I am not sure if this is the best way to do this, but Im pretty positive it will work as long as you can use php to get the incoming link url and change if/else value.
Thanks in advance!
-O
UPDATE: I found this, but not working.
<?php
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'cascarinosonline.com.216-70-85-163.messtudios.com/gallery.php#outside')
{
$page = "gallery";
}
else
{
$page = "galleryfix";
}
;?>
I ditched the php method, and used jquery to find the hash tag and to take the proper action inside the gallery.
if (window.location.hash == "#outside") {
$(".slide-11").addClass("activeslide");
}
All other parameters are echoing and the actual URL and the image is NOT displayed in the results page. I need a shortcut that will display the image itself.
Can I simply write:
$page_picture = ______( $some value['image.jpg'] );
So that $page_picture will display the image related to its associated URL?
All suggestions are welcome.
Just do this....
echo "<img src='".$page_picture."'>";
Assuming $page_picture is the url to your image, such as http://www.domain.com/img/blahblah.jpeg
If you wanna also link to the original image, when they click...
echo "<a href='".$page_picture."' target=_blank><img src='".$page_picture."'></a>";
I'm completely new to creating dynamic pages - so for the moment, I am using txt files to manage my simple data! I'll explain my set up first. I have one php page - it gets data from two .txt files:
brief.txt: written content (title and supporting text)
photos.txt: image file names.
I am using php pagination, and this changes the content in the php page by referring to the numbers I have used in the .txt file, here is the code I am using:
<?php
$data=file("brief.txt");
$pages=0;
foreach($data as $temp){
$x=explode("|",$temp);
if($x[0]>0){
$pages=$pages+1;
}
}
if($_GET['p']){
$page=$_GET['p'];
}
if($_GET['i']){
$index=$_GET['i'];
}
if($index == "p"){
$page=$page-1;
}
if($index == "n"){
$page=$page+1;
}
if($page < 1){
$page=1;
}
if($page > $pages){
$page=$pages;
}
$line=$data[$page-1];
$fields=explode("|",$line);
?>
and this is an example of my text file
brief.txt:
1|TITLE 1|Content goes here
2|TITLE 2|Content goes here
photos.txt:
1|imageone1.jpg
2|imagetwo1.jpg
Hopefully that all makes sense! Now, my problem is, I have a few video files. At the moment, the images load in a jquery slideshow. I would like to somehow have the script change, for example, when it makes page 3 with a video file it doesn't create the slideshow, but instead creates a video player and can load the url of my video that is placed in the txt file. The code I am using at the moment for the jquery slideshow is this:
<?php
echo"
<div id='portfolioslider'><div class='slider'>";
$photos=file("photos.txt");
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
echo"<div><img src='images/work/$photo' alt='' /></div>\n";
}
}
echo"</div></div>"?>
I would like the above code, to change similar to this when you go to a page with a video:
<iframe src="http://player.vimeo.com/video/23024550?title=0&byline=0&portrait=0" width="1024" height="576" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>
And if you go back or forward to a page which doesn't have a video, I would like it to change back to the original jquery slideshow...
Please can someone help me out with the necessary code I would need to make this work! I am very much a beginner coder :(
Edit: Assuming I understand your logic's structure, and it's possible I missed something:
Perhaps, using a videos.txt to store videos, as opposed to putting both inside of photos.txt? Also, look into using a MySQL database for this.
And if you absolutely must use this manner of coding, I'd create a function that accepts a file name, and depending on the extension determines if it is a video or an image, thus dictating what content to load, and how.
Or, you can add an extra flag to your photos.txt file:
1|blah|1
2|blahblah|0
Where the third '1' means video, and a '0' means photo? It's your metadata, so you can dictate its structure.
Basically what you need to do is just check to see if the current file is a picture or a video. The easiest way would be to look at the extension. Your videos are also stored in photos.txt, right? try something like this:
<?php
$photos=file("photos.txt");
// since you already know the page number, you can just skip to that index instead of looping through the entire file
$item = explode("|",$photos[$page-1]);
$photo = trim($item[1]);
//lets see if it's a photo or a video
if(substr($photo,-3) == 'jpg') {
//echo out code for images here
} else {
//echo out code for video here
}
?>
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)?