Jump to content

Adding html to php variable?


hlstriker

Recommended Posts

Hi, I am trying to add html to a php variable so it can then send the HTML code to a field in my database. (Yes I want the html code itself to be sent to the database!)

I get "unexpected T_STRING" error for this code...
[code]$html = "<tr>
<td valign='top' align='center' bgcolor='#212121'>
<a href='#' onmouseover="roll_over('name', 'http://www.mysite.com/image-hover.jpg')" onmouseout="roll_over('name', 'http://www.mysite.com/image.jpg')">
<img border='0' src='http://www.mysite.com/image.jpg' name='name'></a>
</td>
</tr>"[/code]

The error line is where I start the link. I think it is because of the double quotes, but I don't know how to bypass this because if I put the single quotes in the link, the javascript won't function.

If someone could tell me how to do this please do! Thanks!
Link to comment
https://forums.phpfreaks.com/topic/24803-adding-html-to-php-variable/
Share on other sites

Hi,

You are getting this error because you use just ", you should use \" becuse you have started with ".

i feel its better to do like this.So that you can add HTML as you wish without worrying about the quotes and double quotes

$html = <<START
<tr>
<td valign='top' align='center' bgcolor='#212121'>
<a href='#' onmouseover="roll_over('name', 'http://www.mysite.com/image-hover.jpg')" onmouseout="roll_over('name', 'http://www.mysite.com/image.jpg')">
<img border='0' src='http://www.mysite.com/image.jpg' name='name'></a>
</td>
</tr>
START;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.