frankdm Posted July 23, 2016 Share Posted July 23, 2016 (edited) 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 July 23, 2016 by frankdm Quote Link to comment https://forums.phpfreaks.com/topic/301569-converting-text-hyperlink-to-image-hyperlink/ Share on other sites More sharing options...
frankdm Posted July 24, 2016 Author Share Posted July 24, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/301569-converting-text-hyperlink-to-image-hyperlink/#findComment-1534927 Share on other sites More sharing options...
Psycho Posted July 24, 2016 Share Posted July 24, 2016 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/301569-converting-text-hyperlink-to-image-hyperlink/#findComment-1534929 Share on other sites More sharing options...
Reap38 Posted July 26, 2016 Share Posted July 26, 2016 (edited) When you echo a varecho $var = "SOMETHING";do you see you started with the "" Quotesso 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 July 26, 2016 by Reap38 Quote Link to comment https://forums.phpfreaks.com/topic/301569-converting-text-hyperlink-to-image-hyperlink/#findComment-1535082 Share on other sites More sharing options...
cyberRobot Posted July 26, 2016 Share Posted July 26, 2016 $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. Quote Link to comment https://forums.phpfreaks.com/topic/301569-converting-text-hyperlink-to-image-hyperlink/#findComment-1535084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.