AlnWill Posted January 4, 2013 Share Posted January 4, 2013 In order to service an array of clusters (test results) I use the xsl "for-each" control. I generate a single page per test, but each test has a different image that needs to be displayed on the page. The array contains the image name & path for that test, and so is easy to extract using xsl.I would like to allocate the new image & path name to a variable ($MyImg) for each new iteration of the array.The problem with <img src="FileName.jpg" /> seems to be that src cannot live without the " ", and it seems that you cannot service a tag inside the inverted commas. I've tried putting the <img> tag inside a php tag and tried to read a variable in src=" ". No combination of code has worked.I've tried other forums where a number of people have had the same problem, but no-one seems to have an answer that works. Has anyone got this right? Link to comment Share on other sites More sharing options...
Mudsaf Posted January 4, 2013 Share Posted January 4, 2013 (edited) Misunderstood the problem, my bad. Edited January 4, 2013 by Mudsaf Link to comment Share on other sites More sharing options...
AlnWill Posted January 4, 2013 Author Share Posted January 4, 2013 Hi MudsafI've tried all variations of: <?php $ScanL="ScanLine1.jpg"; print <img src="$ScanL" alt="ScanLine" width="50%" height="50%" border="0" /> ?>For this test I'm just defining the constant $ScanL in order to test the <img> tag.I've also tried placing the <php> tag inside the src inverted commas.I don't follow your href solution -I need to define a variabe for src that gets changed for every iteration of the "for-each" loop. Link to comment Share on other sites More sharing options...
satishpoul Posted January 4, 2013 Share Posted January 4, 2013 use thisprint '<img src="'.$ScanL.'" alt="ScanLine" width="50%" height="50%" border="0" />'; or u can write <img src="<?php echo $ScanL; ?>" alt="ScanLine" width="50%" height="50%" border="0" /> outside php tag Link to comment Share on other sites More sharing options...
AlnWill Posted January 5, 2013 Author Share Posted January 5, 2013 Thanks satishpoul. I still can't get it to work. Is there perhaps anything I need to know about the PHP environment and setup? I'm using Komodo Edit 7.1 and it shows me an 'invalid token' error if I use the 2nd line of code. Link to comment Share on other sites More sharing options...
Ingolme Posted January 5, 2013 Share Posted January 5, 2013 You're working with XSL? In XSL you can create the image like this: <xsl:element name="img"> <xsl:attribute name="src"> <xsl:value-of select=" ... selector here ..." /> </xsl:attribute> <xsl:attribute name="alt">Alternate text</xsl:attribute></xsl:element> In PHP, using variables in HTML attributes just means printing their value along with the HTML. echo '<img src="' . $value . '" alt="alt">'; Link to comment Share on other sites More sharing options...
AlnWill Posted January 5, 2013 Author Share Posted January 5, 2013 Success!!! Ingolme your'e a star!Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now