Jump to content

Recommended Posts

Hey all, thank you for all the great help so far, this is my last question about my hyperlink :) I got this:

 

$content .= "<td> <a href='$varcomplete'>test</a> </td>";

 

This totally works. However I would like to have a image instead of the word "test". This sounds easy but I can't seem to get it working. (keep getting line errors if I try examples I get from the web).. for example this does not work:

 

$content .= "<td> <a href='$varcomplete'><img src="wp-content/custom/imageicon.png" alt="imageicon" border="0"></a> </td>";
 
It gives me the error:
Parse error: syntax error, unexpected 'wp' (T_STRING)
Edited by frankdm

I fixed this, for the record, this was the solution:

 

$content .= "<td> <a href='$varcomplete'><img src=wp-content/custom/imageicon.png" alt="imageicon border="0"></a> </td>";

 

for some reason the " markings needed to be removed (every example on the web had them but removing them worked, go figure :)

I fixed this, for the record, this was the solution:

 

$content .= "<td> <a href='$varcomplete'><img src=wp-content/custom/imageicon.png" alt="imageicon border="0"></a> </td>";

 

for some reason the " markings needed to be removed (every example on the web had them but removing them worked, go figure :)

 

That can't work. If it looks like it is working - it isn't. This is similar to the earlier problem about the href parameter. You need to understand that computer programs require explicit instructions. Humans are very good at deciphering things that may not be in context, but computers are not.

 

When you define a string such as this:

 

$content = "test";

 

The computer sees that you want to define a variable. Then it sees the first double quote which tells it that the following content should be assigned to the variable. When it sees the next double quote it takes that as the end of the content to be assigned. You can also use single quotes to define a string (but there are some different rules on how the content is handled). In your code above you start with a double quote. But then, you have a double quote IN THE CONTENT at the end of the src attribute. So, that is the end of the content that would be assigned to the variable. If you start a string with a double quote, use single quotes inside the string or escape any double quotes in the string. Either of these would work

 

 

$content .= "<td> <a href='$varcomplete'><img src='wp-content/custom/imageicon.png' alt='imageicon' border='0'></a> </td>";

 

 

$content .= "<td> <a href=\"$varcomplete\"><img src=\"wp-content/custom/imageicon.png\" alt=\"imageicon\" border=\"0\"></a> </td>";

When you echo a var
echo $var = "SOMETHING";

do you see you started with the ""  Quotes

so a quote will cancel out code so if you start with qoutes us ' ' as qout marks inside your code.. but f you use ' ' as your start us quotes as your code//
 

$content .= " <td> <a href='$varcomplete'><img src='wp-content/custom/imageicon.png' alt='imageicon' border='0'></a> </td>    "; 

or 
 

$content .= '<td> <a href="$varcomplete"><img src="wp-content/custom/imageicon.png" alt="imageicon" border="0"></a> </td>';

or cancel out the quotes ith back slash
 

$content .= "<td> <a href=\"$varcomplete\"><img src=\"wp-content/custom/imageicon.png\" alt=\"imageicon\" border=\"0\"></a> </td>";
Edited by Reap38
$content .= '<td> <a href="$varcomplete"><img src="wp-content/custom/imageicon.png" alt="imageicon" border="0"></a> </td>';

 

Note that the above string contains a variable. If you enclose the string within single quotes, the variable will not work. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.