I need some help with echoing a <img>
tag with attributes like title, rel, and class.
I have made it this far, when I'm echoing a filename from a db to search in a catalogue to find it. But I'm not sure how to write some attributes to it since I'm going to display it with Pirobox.
This is what i got working:
echo '<a href="uploads/'.$row['bildnamn'].'">';
echo '<img src="uploads/'.$row['thumb_bildnamn'].'">';
echo '</a>';
But I also need these attributes for the <A>
tag which makes the image large.
rel="gallery" class="pirobox_gall" title="$row['uploaded']" . " " . "$row['user']";
What I don't get to work is how to get that line together with:
echo '<a href="uploads/'.$row['bildnamn'].'">';
答案 0 :(得分:3)
你应该能够连接echo '<a href="uploads/' . $row['bildnamn'] . '" rel="gallery" class="pirobox_gall" title="' . $row['uploaded'] . ' ' . $row['user'] . '">';
echo '<img src="uploads/' . $row['thumb_bildnamn'] . '">';
echo '</a>';
标签中的所有内容,如下所示:
title="' . $row['uploaded'] . ' ' . $row['user'] . '"
我插入了空格来帮助强调PHP连接的位置。在您的情况下,单引号开始/结束PHP的字符串;双引号被忽略并进入HTML。所以这一部分:
uploaded
会将标题设为user
列的值,然后是空格,然后是a
列的值。然后,只需使用>
结束C:\Sites\scheduleio>rails s
=> Booting WEBrick
=> Rails 4.2.5.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
C:/Sites/scheduleio/config/initializers/ssl_configuration.rb:5: warning: already initialized constant OpenSSL::SSL::VERIFY_PEER
Exiting
代码。
答案 1 :(得分:0)
你可以继续连接字符串
echo '<a href="uploads/'.$row['bildnamn'].'"'. 'rel="gallery" class="pirobox_gall" title="'.$row['uploaded'].' '.$row['user'].'">';
答案 2 :(得分:0)
试试这个:
echo '<a href="uploads/' . $row['bildnamn'] . '" rel="gallery" class="pirobox_gall" title="' . $row['uploaded'] . ' ' . $row['user'] . '">';
echo '<img src="uploads/' . $row['thumb_bildnamn'] . '">';
echo '</a>';
答案 3 :(得分:0)
您可以使用字符串连接执行此操作,如下所示:
for(String token : tokens)
{
att[i] = token;
i++;
//Print all tokens
// System.out.println(token);
System.out.println(att[1]);
break; // <---- ***take this out***
}