The problem is : Imagine that I have 10 posts. Each of these has 1 title 1 content and images. Some of my posts do not have images at all. For example, the title of post 4 will be saved to variable "vartitles4", the content to "varcontents4" and the image to "varimages4". If post 4 does not have any images, it means that "varimages4" will have the value that was meant to be saved on "varimages5". (so varimages10 value will be null at the end)
So, how can I assign a value like a non-image.gif to varimages4 so that the script will work properly ?
Below is the code that gets the images. I have another two blocks of code like this one (title-content) before that.
Expand|Select|Wrap|Line Numbers
- $img = $xPathimages->query('//div[@class="entry"]//img');
- $thefirst = 1;
- $iimg=0;
- foreach ($img as $imgs) {
- $images = $imgs->getAttribute('src');
- ${'varimages' . $iimg} = $images; //the value is saved to varimages1/2/3/4/5/6...
- if($thefirst == 1) break; //gets only the first image
- $iimg=$iimg+1;
- }