parse error, unexpected T_CONSTANT_ENCAPSED_STRING

I'm getting a parse error - parse error, unexpected
T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' - on this line of
code:

"oFCKeditor.Value = "; echo preg_replace"(\"/\r\n/\", \"\\n\",
addslashes(\"" . $VAR . "\"))";

it is part of a larger block:

if (!empty($query_data['VAR'])) {
echo "<table width=\"85\" border=\"0\" cellpadding=\"0\" cellspacing=
\"0\">\n".
"<tr>
<td scope=\"col\"> </td>\n".
"<td scope=\"col\"><b>TEXT </b></td>\n".
"<td scope=\"col\"> </td>\n".
"</tr>
<tr>
<td scope=\"row\"> </td>\n".
"<td><!-- <textarea name=\"NAME\" cols=
\"65\" rows=\"5\" id=\"NAME\"></textarea> -->\n".

"<script type=\"text/javascript\">\n".

"var oFCKeditor = new FCKeditor( 'NAME ) ;\n".
"oFCKeditor.BasePath = \"http://nominations.aacrao.org/activity/
fckeditor/\";\n".
"oFCKeditor.Width=500 // in pixel or %, default='100%'\n".
"oFCKeditor.Height=500; // in pixel or %, default 0\n".
"oFCKeditor.ToolbarSet = 'Default';\n".


"oFCKeditor.Value = "; echo preg_replace"(\"/\r\n/\", \"\\n\",
addslashes(\"" . $VAR . "\"))";


echo "oFCKeditor.Create() ;\n".
"</script>
</td>
</table>\n";
} else {
}

I need this to work the same as:

<script type="text/javascript">
var oFCKeditor = new FCKeditor( 'NAME' ) ;
oFCKeditor.BasePath = "http://nominations.aacrao.org/activity/
fckeditor/";
oFCKeditor.Width=500 // in pixel or %, default='100%'
oFCKeditor.Height=500; // in pixel or %, default 0
oFCKeditor.ToolbarSet = 'Default';
oFCKeditor.Value = "<?php echo preg_replace("/\r\n/", "\
\n",addslashes($VAR)); ?>";
oFCKeditor.Create() ;
</script>

but each time that I try a different instance of setting the editor I
get another error. I can get it to render basic text but the preg
replace and addslashes are necessary to get HTML tags to render
correctly and that's where the problem is. I've been able to have it
pull the variable with the html tags using a basic line:

"oFCKeditor.Value = \" " . $VAR ."\";\n".

but if there is any HTML then it doesn't display correctly and I get a
syntax error and things don't come through.

Can anyone take a look and see where I'm making the error in the
escaping of the problem line?

Thanks,
Chris
christopher.j.just [ Di, 22 Mai 2007 18:18 ] [ ID #1718588 ]

Re: parse error, unexpected T_CONSTANT_ENCAPSED_STRING

On May 22, 12:18 pm, christopher.j.j... [at] gmail.com wrote:
> I'm getting a parse error - parse error, unexpected
> T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' - on this line of
> code:
>
> "oFCKeditor.Value = "; echo preg_replace"(\"/\r\n/\", \"\\n\",
> addslashes(\"" . $VAR . "\"))";
>
> it is part of a larger block:
>
> if (!empty($query_data['VAR'])) {
> echo "<table width=\"85\" border=\"0\" cellpadding=\"0\" cellspacing=
> \"0\">\n".
> "<tr>
> <td scope=\"col\"> </td>\n".
> "<td scope=\"col\"><b>TEXT </b></td>\n".
> "<td scope=\"col\"> </td>\n".
> "</tr>
> <tr>
> <td scope=\"row\"> </td>\n".
> "<td><!-- <textarea name=\"NAME\" cols=
> \"65\" rows=\"5\" id=\"NAME\"></textarea> -->\n".
>
> "<script type=\"text/javascript\">\n".
>
> "var oFCKeditor = new FCKeditor( 'NAME ) ;\n".
> "oFCKeditor.BasePath = \"http://nominations.aacrao.org/activity/
> fckeditor/\";\n".
> "oFCKeditor.Width=500 // in pixel or %, default='100%'\n".
> "oFCKeditor.Height=500; // in pixel or %, default 0\n".
> "oFCKeditor.ToolbarSet = 'Default';\n".
>
> "oFCKeditor.Value = "; echo preg_replace"(\"/\r\n/\", \"\\n\",
> addslashes(\"" . $VAR . "\"))";
>
> echo "oFCKeditor.Create() ;\n".
> "</script>
> </td>
> </table>\n";
>
> } else {
> }
>
> I need this to work the same as:
>
> <script type="text/javascript">
> var oFCKeditor = new FCKeditor( 'NAME' ) ;
> oFCKeditor.BasePath = "http://nominations.aacrao.org/activity/
> fckeditor/";
> oFCKeditor.Width=500 // in pixel or %, default='100%'
> oFCKeditor.Height=500; // in pixel or %, default 0
> oFCKeditor.ToolbarSet = 'Default';
> oFCKeditor.Value = "<?php echo preg_replace("/\r\n/", "\
> \n",addslashes($VAR)); ?>";
> oFCKeditor.Create() ;
> </script>
>
> but each time that I try a different instance of setting the editor I
> get another error. I can get it to render basic text but the preg
> replace and addslashes are necessary to get HTML tags to render
> correctly and that's where the problem is. I've been able to have it
> pull the variable with the html tags using a basic line:
>
> "oFCKeditor.Value = \" " . $VAR ."\";\n".
>
> but if there is any HTML then it doesn't display correctly and I get a
> syntax error and things don't come through.
>
> Can anyone take a look and see where I'm making the error in the
> escaping of the problem line?
>
> Thanks,
> Chris

Never mind... figured out a solution that works cross platform.
christopher.j.just [ Di, 22 Mai 2007 22:15 ] [ ID #1718590 ]

Re: parse error, unexpected T_CONSTANT_ENCAPSED_STRING

christopher.j.just [at] gmail.com wrote:
> On May 22, 12:18 pm, christopher.j.j... [at] gmail.com wrote:
>> I'm getting a parse error - parse error, unexpected
>> T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' - on this line of
>> code:
>>
>> "oFCKeditor.Value = "; echo preg_replace"(\"/\r\n/\", \"\\n\",
>> addslashes(\"" . $VAR . "\"))";
>>
>> it is part of a larger block:
>>
>> if (!empty($query_data['VAR'])) {
>> echo "<table width=\"85\" border=\"0\" cellpadding=\"0\" cellspacing=
>> \"0\">\n".
>> "<tr>
>> <td scope=\"col\"> </td>\n".
>> "<td scope=\"col\"><b>TEXT </b></td>\n".


You use a quite messy way to echo out your data, it can be much easier if you
store result from functions into variables and then use

echo <<<EOF
<your html tags>{$values_you_want_to_inject_into_the_html}</more html tags>
EOF;

That way you can use " without any escape character before and you see things
a lot easier.
--

//Aho
Shion [ Mi, 23 Mai 2007 06:43 ] [ ID #1720957 ]
PHP » alt.php » parse error, unexpected T_CONSTANT_ENCAPSED_STRING

Vorheriges Thema: The Relative Importance of Web Development
Nächstes Thema: PHP web design patterns