Reputation: 1665
Can anyone give me a solution for the below lines of code:
$filteredArray = array_filter($wordArray, function ($x) {
return !preg_match("/^(.|a|an|and|the|this|at|in|or|of|is|for|to|em|com|be
|with|href|me|rt|by|np|http|www)$/x", $x);
});
This line not producing any error in my localhost using XAMPP, but the same line is showing an error in my nginx server (online).
What can I do for this. Why this is showing?
Upvotes: 0
Views: 390
Reputation: 270775
Sounds like your server may not be running PHP 5.3 or later, which is needed to support anonymous functions. Instead, you can create the function and pass it as a callback function string to array_filter()
.
function wordFilter($x) {
return !preg_match("/^(.|a|an|and|the|this|at|in|or|of|is|for|to|em|com|be
|with|href|me|rt|by|np|http|www)$/x", $x);
}
$filtered_array = array_filter($wordArray, 'wordFilter');
Upvotes: 2
Reputation: 191819
Your version of php on the nginx server is too old to use anonymous functions (closures -- at least PHP 5.3) is required. You can use create_function
to create a function in older versions, and that still works in newer versions as well.
Upvotes: 0