note 17235 deleted from function.eval by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 23:26:38 +0000 |
| Subject: | note 17235 deleted from function.eval by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22332@lists.php.net to get a copy of this message | ||
I came looking for what I recently discovered about a month ago and I'm surprised how simple
the eventual solution is, and that nobody brought it up earlier. I tried many of the aforementioned
notes and none of them worked for me.
If you're trying to parse a template, or other file that has HTML code (either at the beginning
or anywhere within it), you will most likely receive a parse error.
For example, this is the template:
--
<table width="400" cellspacing="2" cellpadding="2"
border="0">
<tr>
<td bgcolor=$coloursecond class="small">The following represents the terms and
conditions required for a passport issued by $companyname</td>
</tr>
<tr>
<td bgcolor=$colourcontrast class="contrast"><b>Terms of
Use</b></td>
</tr>
<tr>
<td bgcolor=$colourmid class="mid"><ul>
<li>blah blah blahck sheep</li>
</ul></td>
</tr>
</table>
--
The reason you receive parse errors with this code is because of the attributes found in the HTML
tags, not the HTML itself. Because of the ""s, it will not parse correctly, just as if you
created a $block="she told me I was "great"";, without the slashes.
Here is the correct code to retrieve this template:
$templatefile="suite/templates/passports-terms.inc";
$body=fopen($templatefile,"r");
$body=fread($body,filesize($templatefile));
// add slashes
$body=addslashes($body);
eval("\$body=\"$body\";");
From what I discovered, simply adding slashes to the file output before EVAL will alleviate this
problem.
I also recommend not using ""s when assigning numeric-only values to PHP or HTML
attributes - its unnecessary and creates more work for you.
For example:
<table width="400" bcolor="#777777">
should become:
<table width=400 bgcolor=#777777>