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
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"] . '" \'); ';
?>

 

Link to comment
Share on other sites

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"] . '" \');
?>

Link to comment
Share on other sites

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.

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.