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
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;

Link to comment
Share on other sites

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.