We help IT Professionals succeed at work.
Get Started

PHP Array To String Notice

Robert Granlund
on
424 Views
Last Modified: 2015-04-05
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:
	 return str_replace(LD.$name.RD, $value, $string);

Open in new window


<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>

Open in new window

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);

	}

Open in new window

Comment
Watch Question
Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE