Robert Granlund
asked on
PHP Array To String Notice
I get the following notice on my webpage.
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: libraries/Template.php
Line Number: 3859
The line number 3859 is this:
The following is the entire Method. It is part of the Expression Engine CMS. Maybe it can be defined in here someplace?
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: libraries/Template.php
Line Number: 3859
The line number 3859 is this:
return str_replace(LD.$name.RD, $value, $string);
<div class="controls">
{select id="bike_type"}
{if option_first_row}<option value="">Select a Value</option>{/if}
<option {selected} value="{option_value}" >{option_name}</option>
{/select}
</div>
The Notice goes away if I remove value="{option_value}". It does not like the curly brackets. How can I change this so it is okay with the curly brackets?The following is the entire Method. It is part of the Expression Engine CMS. Maybe it can be defined in here someplace?
function _parse_var_single($name, $value, $string)
{
// parse date variables where applicable
if (in_array($name, (array) $this->date_vars))
{
return $this->parse_date_variables($string, array($name => $value));
}
// Simple Variable - Find & Replace & Return
if (is_string($value))
{
return str_replace(LD.$name.RD, $value, $string);
}
//
// Complex Paths and Typography Variables
//
// If the single variable's value is an array, then
// $value[0] is the content and $value[1] is an array
// of parameters for the Typography class OR an indicator of a path variable
if (is_array($value) && count($value) == 2 && is_array($value[1]))
{
$raw_content = $value[0];
// Make our path switches
if (isset($value[1]['path_variable']) && $value[1]['path_variable'] === TRUE)
{
if (preg_match_all("#".LD."\s*".$name."=(.*?)".RD."#", $string, $matches))
{
$done = array();
foreach ($matches[0] as $full)
{
if (in_array($full, $done))
{
continue;
}
$link = ee()->functions->create_url(ee()->functions->extract_path($full).'/'.$value[0]);
//$single_quote = str_replace("'", '"', $matches['0']);
//$double_quote = str_replace("'", '"', $matches['0']);
//[0] => {id_path="about/test"}
//[1] => "about/test"
// Switch to double quotes
$single = str_replace(array('"', "'"), "'", $full);
$double = str_replace(array('"', "'"), '"', $full);
//echo $single.' - '.$double.'<br>';
$string = str_replace($single, $double, $string);
//echo $string;
//echo '<br>-----------------------<br>';
$string = str_replace($double, $link, $string);
$done[] = $full;
}
}
return $string;
}
$prefs = array();
foreach (array('text_format', 'html_format', 'auto_links', 'allow_img_url', 'convert_curly') as $pref)
{
if (isset($value[1][$pref]))
{
$prefs[$pref] = $value[1][$pref];
}
}
// Instantiate Typography only if necessary
ee()->load->library('typography');
ee()->typography->initialize(array(
'convert_curly' => (isset($prefs['convert_curly']) && $prefs['convert_curly'] == 'n') ? FALSE : TRUE)
);
$value = ee()->typography->parse_type($raw_content, $prefs);
}
if (isset($raw_content))
{
$this->conditional_vars[$name] = $raw_content;
}
// SPOKE Modification. I commented out the return. It was causing a PHP Notice. It is because it does not like any info inside of an option.
return str_replace(LD.$name.RD, $value, $string);
}
That error typically occurs when you try to access an array as a string. Even when all the array elements are strings, you have to pass them individually in the format $array[0] or $array['name']. (Substitute the name of your array in place of 'array') You can't pass the whole array.
ASKER
I'm not sure I understand that as it applies to what I have posted. Can you elaborate just a little more?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
After reading and re-reading the comments and suggestions, I realized that with Expression Engine at times you need to use tag pairs to take care of the Curly Bracket issue. Thanks for getting me on the correct path.