Warning: Unexpected character in input: '\' (ASCII=92) state=1
You cannot accomplish this with a simple preg_replace
, as array de-referencing is not done with /e
modifier. Instead you can use preg_replace_callback
function:
$tag_value = preg_replace_callback("/\{(.*?)\}/", function($m) use($values){
return $values[$m[1]];
}, $tag_value);
This definitely works in php 5.3, however in 5.2 you may need to define the callback function explicitly:
function replace($m) {
global $values;
return $values[$m[1]];
}
$tag_value = preg_replace_callback("/\{(.*?)\}/", "replace", $tag_value);
EDIT: The error you are seeing is happening because with your original code, your substitution is being treated literally as $values[\1]
(after unescaping the backslash - in this string, \1
is not the right stuff to put inside the brackets.
Unexpected character in input: '\' (ASCII=92) state=1 in a Silex Application
According to the official documentation, Silex requires PHP 5.3 to provide namespace support.
Try to migrate your server to PHP 5.3 in order to get rid of this error.
Silex is a PHP microframework for PHP 5.3.
Warning: Unexpected character in input: '\' (ASCII=92) state=0
Quoting from the Wiki here on StackOverflow
PHP 6
On July, 30th, 2014 a majority of the PHP steering group decided to skip version 6 to avoid confusion with an earlier but abandoned PHP 6 project (dubbed the Unicode release). While there never was any official release of PHP 6, many books and articles had been published already.
PHP 6 Does not exist, and never will officially exist. It was completely deleted from the version control repository.
The fact that AppServ still provides access to AppServ 2.6.0 show a complete lack of responsibility on their part.
The latest official version of PHP is 5.6.13, use that official release. The next major release (around November 2015) will be PHP 7.... there will be no PHP 6
Unexpected character in input: '\'
There's probably cli php version 5.4 available, ask Bluehost for the full path and use it.
Related Topics
Convert Flat Array to the Multi-Dimensional
What Causes: "Notice: Uninitialized String Offset" to Appear
Populate Another Select Dropdown from Database Based on Dropdown Selection
Using PHP to Populate a <Select></Select> Dropdown
Laravel Eloquent Display Query Log
How to Change/Custom Password Field Name for Laravel 4 and Laravel 5 User Authentication
How to Setup Table Prefix in Symfony2
PHP Parse Error: Syntax Error, Unexpected T_Object_Operator
Laravel Trailing Slashes Redirect to Localhost
New Limit Within PHP: 1000 Fields Per Post. Does Someone Know, If the Number Can Be Influenced
How to Store Null Values in Datetime Fields in MySQL
PHP Emitting 500 on Errors - Where Is This Documented
Laravel Request::All() Should Not Be Called Statically
How to Count Unique Visitors to My Site