Hello,

I have this Warning with the page /admin/build/translate page:

warning: preg_match() expects parameter 2 to be string, array given in /home/pariscin/www/includes/bootstrap.inc on line 771

I really don't know where this warning message come from, and what it means.

Any ideas?

Thanks :)

Comments

elektrorl’s picture

exactly the same error

Junro’s picture

Hum maybe I have something.

Did you add into the header or footer of a page view a text with php and t function?

Junro’s picture

l. 734 in bootstrap.inc

Adding the following right at the beginning of the function fixe the problem.
if (is_array($text)) return '';

see: http://drupal.org/node/320145

But it's a core fixe and not very good. A module should be the cause.

WorldFallz’s picture

It's also exposing a security risk.

boran’s picture

I also came across this when listing "/admin/content/taxonomy/3" (with D6.14)
The error was

warning: preg_match() expects parameter 2 to be string, resource given in /var/www/includes/bootstrap.inc on line 777

My fix was to cast the string to make sure it really is a string, a call to htmlspecialchars() had the same issue:

diff -r1.1 /var/www/includes/bootstrap.inc
741c741,742
<   return drupal_validate_utf8($text) ? htmlspecialchars($text, ENT_QUOTES) : '';
---
>   return drupal_validate_utf8($text) ? htmlspecialchars((string)$text, ENT_QUOTES) : '';
777c778,779
<   return (preg_match('/^./us', $text) == 1);
---
>   return (preg_match('/^./us', (string) $text) == 1);

Any comments on this fix, is this an improvement that could be suggested for core?

Alex Andrascu’s picture

Your fix is working and seems like a viable solution. But i'm not a guru in php

colorado’s picture

Thank you very much!

faffo’s picture

with my issue http://drupal.org/node/640380, i have the same problem, at this function i passed an array of id, using views argument taxonomy.

is it correct to add this code?


if(is_array($text)){
$text=implode(",",$text);
}

is the rigth thing add this code to drupal core ?

thanks

boran’s picture

Seems right, you are checking the type and acting accordingly.

ademskiadov’s picture

Encountered the same issue after trying to add items to a custom built menu (in the context of adding new icons to the top bar in rootcandy theme). boran's fix worked for me. Good job and thank you.

srobert72’s picture

I can confirm your patch solves my problem.
It doesn't repair module that really causes this issue.
But it works.

------------------------------------------------

http://www.ilemaurice-bonplan.com

lardi’s picture

Thanks boran for this solution

arthursk’s picture

Thanks Boran,

I had the same issue this morning with 6.16, I've applied these two changes to the bootstrap file and it seems to be listing terms without error.

Arthur

srobert72’s picture

Today Drupal 6.17 is released.
Patch needs to be updated :

includes/bootstrap.inc line 842

return (preg_match('/^./us', (string) $text) == 1) ? htmlspecialchars((string) $text, ENT_QUOTES, 'UTF-8') : '';

And it's work. Thank you again @boran.

------------------------------------------------

http://www.ilemaurice-bonplan.com

ClearXS’s picture

Yes, it works! (for me with fusioncharts sub-module of Charts)

But is this the way, or should individual modules that cause these errors be changed INSTEAD?

And if this is the way, where is the official bug report and the official patch to implement this in the next core release?

pimok3000’s picture

The patch works although i had to change line 840 inbetween

 if ($php525) 
{
    return (preg_match('/^./us', (string) $text) == 1) ? htmlspecialchars((string) $text, ENT_QUOTES, 'UTF-8') : '';
}
    return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
zoo’s picture

@torstenzenk,

I can confirm your way worked for me too. But (@anyone) is this the right procedure to fix the problem?

thanks

yakker’s picture

subscribing

colan’s picture

This will make the error go away, but it is incorrect logically. See http://drupal.org/node/829250#comment-3148784 for details.

MatthijsG’s picture

Also working for me.

======
There are 10 people who can count binary
They who can and they who don't

Rosamunda’s picture

Comment 3110966 works for me. But it´s a patch or a hack?
I´ve checked all my modules, updated them and the error persists. So I´ve tried the patch and it works.

Is it safe? Is it a patch? Will it be commited? As I´m not a developer, I don´t feel good about patching/hacking core...

Thanks for the patch!

Fidelix’s picture

subscribing

robbm’s picture

Fixed warning: htmlspecialchars() expects parameter 1 to be string, array given in /srv/www/htdocs/includes/bootstrap.inc on line 840. in Workflow for me.

xbl’s picture

subscribing for this issu and thx again 2 Boran!

Screenack’s picture

Modifying lines 840 + 842 fixed my problem

jnojr’s picture

Ever since applying this patch, I now get:

Invalid argument supplied for foreach() in /var/www/html/includes/theme.inc on line 1200.

And, where Books are supposed to be, there's what looks like a button that says "Array", but it is not a button that can be pressed.

qinwubi’s picture

Works for me too. Thanks!

ataxia’s picture

I started getting this error immediately after upgrading to Drupal 6.15.

Modifying bootstrap.inc worked for me! Thanks, Boran!

- ataxia

srobert72’s picture

Subscribing

------------------------------------------------

http://www.ilemaurice-bonplan.com

Anonymous’s picture

Thanks, Boran. I spent about an hour trying to figure out what was causing this precisely. Your fixed worked like a charm!

Junro’s picture

Waou, just figure out what module is responsable for my "warning: preg_match.... bootstrap.inc on line 771 with /admin/build/translate page"

Amazon Store module is responsable in my cause :)

I create an Amazon Store issue: #740796: warning: bootstrap.inc on line 777 with Amazon Store module enable

my-family’s picture

I have this error after installing Content Profile module, adding a new group (CCK) to the "profile" content type and go to the edit page of the group.

my-family’s picture

Finally, I discovered that my problem was in Conditional Fields module. Upgrading the CF module to 6.x-1.1 solved it.

bredi’s picture

I had an older version of Conditional Fields, Not enabled. But thought I'd enable and update it.

This didn't work for me. bummer.

changing

return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';

to

return (preg_match('/^./us', $text) == 1) ? htmlspecialchars((string) $text, ENT_QUOTES, 'UTF-8') : '';

did.

bredi

jnojr’s picture

I'm using RHEL5, which ships with PHP 5.1.6 In bootstrap.inc I see:

function check_plain($text) {
static $php525;

if (!isset($php525)) {
$php525 = version_compare(PHP_VERSION, '5.2.5', '>=');
}
// We duplicate the preg_match() to validate strings as UTF-8 from
// drupal_validate_utf8() here. This avoids the overhead of an additional
// function call, since check_plain() may be called hundreds of times during
// a request. For PHP 5.2.5+, this check for valid UTF-8 should be handled
// internally by PHP in htmlspecialchars().
// @see http://www.php.net/releases/5_2_5.php
// @todo remove this when support for either IE6 or PHP < 5.2.5 is dropped.

if ($php525) {
return htmlspecialchars((string)$text, ENT_QUOTES, 'UTF-8');
}

return (preg_match('/^./us', (string) $text) == 1) ? htmlspecialchars((string) $text, ENT_QUOTES, 'UTF-8') : '';

Since it appears to be checking for PHP 5.2, is it barfing on 5.1? With the fix as applied above, my site is horribly broken... images do not show up, all sorts of things are missing or broken. If I remove the "(string)" from those two lines, the site works again, but I'm again flooded with preg_match errors.

sansui’s picture

subscribing

jnojr’s picture

Still really hoping someone can provide an answer!

nightlife2008’s picture

Hi guys, I did a backtrace using debug_print_backtrace() and the originating function sending an array to the check_plain function is "content_content_field_content_type_content_types()" which does a "t()" providing the Array on which the "htmlspecialchars()" function fails.

The involved modules (in my case) are a combination of Ctools and Panels.

Below I will include the first 6 entries of the backtrace log for anyone who wants it :) I have removed any long strings for easier readability.

#0 check_plain(Array ([nl] => Array (...$data...))) called at [/var/vhosts/website/includes/common.inc:932]
#1 t(Field: @widget_label (@field_name) - @field_type, Array ([@widget_label] => Visibility,[@field_name] => field_ma_visibility,[@field_type] => Array ([nl] => Array ()))) called at [/var/vhosts/website/sites/all/modules/cck/includes/panels/content_types/content_field.inc:40]
#2 content_content_field_content_type_content_types(Array ()) called at [/var/vhosts/website/sites/all/modules/ctools/includes/content.inc:149]
#3 ctools_content_get_subtypes(Array ()) called at [/var/vhosts/website/sites/all/modules/ctools/includes/content.inc:630]
#4 ctools_content_get_available_types(Array (), , Array (), Array ([other] => 1)) called at [/var/vhosts/website/sites/all/modules/panels/includes/common.inc:356]
#5 panels_common_get_allowed_types(panels_page, Array ()) called at [/var/vhosts/website/sites/all/modules/panels/panels.module:1414]

For anyone who also wants to find out where the Array (or not-string) variable comes from on their installation do as follows:

Edit includes/bootstrap.inc around line 842 and add the fragment between "static $php525" and "if (isset($php525)) {" as follows:

function check_plain($text) {
  static $php525;

  if ( !is_string($text) && is_array($text) ) {
    echo "<pre>";
    print_r($text);
    debug_print_backtrace();
    echo "</pre>";
  }
  if (!isset($php525)) {
    $php525 = version_compare(PHP_VERSION, '5.2.5', '>=');
  }
  // We duplicate the preg_match() to validate strings as UTF-8 from
  // drupal_validate_utf8() here. This avoids the overhead of an additional
  // function call, since check_plain() may be called hundreds of times during
  // a request. For PHP 5.2.5+, this check for valid UTF-8 should be handled
  // internally by PHP in htmlspecialchars().
  // @see http://www.php.net/releases/5_2_5.php
  // @todo remove this when support for either IE6 or PHP < 5.2.5 is dropped.

  if ($php525) {
    return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  }
  return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
}

Have fun debugging.

/Kim

wicki’s picture

subscribing