Jump to content

unexpected T_CONSTANT_ENCAPSED_STRING


phily245

Recommended Posts

Hi,

 

I'm making a script that generates an array by using a while loop and a start and end date. The while loop will echo the array out perfectly, but I need it stored, not echoed. In an attempt to create the array, I made this script:

<?php 
$dated = date("dmY", $date);

$eventarray[]='array(' "month" => '" . dated["2"] . =$dated["3"] . "', "day" => '" . $dated["0"] . $dated["1"] . "', "year" => '" . =$dated["4"] . $dated["5"] . $dated["6"] . $dated["7"] . "' ); ';
?>

 

However, when I run the script, I get the error message "unexpected T_CONSTANT_ENCAPSED_STRING".

 

This is the array which it needs to put out when the start date 14-07-2011 and the enddate is 21-07-2011:

 

array( "month" => 07, "day" => 14, "year" => 2011 ); array( "month" => 07, "day" => 15, "year" => 2011 ); array( "month" => 07, "day" => 16, "year" => 2011 ); array( "month" => 07, "day" => 17, "year" => 2011 ); array( "month" => 07, "day" => 18, "year" => 2011 ); array( "month" => 07, "day" => 19, "year" => 2011 ); array( "month" => 07, "day" => 20, "year" => 2011 ); array( "month" => 07, "day" => 21, "year" => 2011 );

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/242534-unexpected-t_constant_encapsed_string/
Share on other sites

Here is the revised code:

 

<?php
$dated = date("dmY", $date);

$eventarray[]='array(\' "month" => "' . dated["2"] . $dated["3"] . '", "day" => "' . $dated["0"] . $dated["1"] . '", "year" => "' . $dated["4"] . $dated["5"] . $dated["6"] . $dated["7"] . '" \'); ';
?>

 

I found what was wrong, I didn't need to put the entire array section in single quotes. Here is the new code:

<?php
$eventarray[]= array(\' "month" => "' . dated["2"] . $dated["3"] . '", "day" => "' . $dated["0"] . $dated["1"] . '", "year" => "' . $dated["4"] . $dated["5"] . $dated["6"] . $dated["7"] . '" \');
?>

If your trying to add an actual array to the $eventarray array your still going about it wrong.

 

For example.

 

$eventarray[]= array("month" => dated["2"] . $dated["3"], "day" => $dated["0"] . $dated["1"]);

 

Sorry for the confusion but your code was so far off track I assumed you where trying to insert a string.

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.