Jump to content

Using a variable for Img Src


AlnWill

Recommended Posts

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...