php - Problem with values on a foreach loop and how can I assign the correct value to the correct variable -
I have a blog, and I have a script to show my post (title-content-image) in another page I'm making me with the code below The first image of the post is found in the problem: Imagine that I have 10 posts. Each of them has 1 title 1 content and images. Images in my post are not at all. For example, the title of post 4 will be saved in the "vartitles4" variable, the content will be saved in "varcontents4" and the image will be saved in "varimages4" if the post 4 does not have any image That "varimages4" would have the value that had to be saved on "varimages5". (So the varimages10 value will eventually be empty) So, how can I assign values like varimages4 to a non-image.gif so that the script works properly? The code below gives the picture before I have another two block code, such as this (title-content). Thank you guys! Yes, it will not be: Give me $ xPathimages- & gt; The results of the query () are not ... so maybe this is where the "item (0)" will come in play. & lt; Div class = "entry" & gt;
$ img = $ xpathimages-> Query ('// div [@ class = "entry"] // img'); $ Thefirst = 1; $ Iimg = 0; Foreign Currency ($ img $ as imgs) {$ images = $ imgs- & gt; GetAttribute ('src'); $ {'Varimages' $ Iimg} = $ Picture; // value is saved for varimages1 / 2/3/4/5/6 ... if break ($ thefirst == 1); // Only the first image gets $ iimg = $ iimg + 1; }
$ imgs = $ XPathimages- & gt; Query ('// div [@ class = "entry"] // img'); $ First image = $ image [0];
$ first image = $ imgs- & gt; Item (0);
Comments
Post a Comment