开发者

PHP Illegal offset type

Warning: Illegal offset type in /email_HANDLER.php on line 85

$final_message = str_replace($from, $to, $final_message);

preg_match_all('/<img[^>]+>/i',$final_message, $result);
$img = array();
foreach($result as $img_tag)
{
    preg_match_all("/(alt|title|src)=('[^']*')/i",(string)$img_tag, $img[$img_tag]); //LINE 85
}

Anyone? I'm about to tear my hair out over this...

here is my var_dump of $img_tag

array(1) {
  [0开发者_如何学C]=>
  string(97) "<img alt='' src='http://pete1.netsos.com/site/files/newsletter/banner.jpg' align='' border='0px'>"


Assuming $img_tag is an object of some type, rather than a proper string, cast $img_tag to a string inside the []

preg_match_all("/(alt|title|src)=('[^']*')/i",(string)$img_tag, $img[(string)$img_tag]);
//------------------------------------------------------------------^^^^^^^^^

Some object types, notably SimpleXMLElement for example, will return a string representation to print/echo via the magic method __toString(), but cannot stand in as regular strings. Attempts to use them as array keys will yield the illegal offset type error unless you cast them to proper strings via (string)$obj.


See first comment on this PHP bug report:

You cannot use arrays or objects as keys. Doing so will result in a warning: Illegal offset type. Check your code.

Ensure that $img_tag is of the appropriate variable type.


$result is 2-dimentional array.So, $img_tag should be an array.

But only integers and strings may be used as offset


foreach( $result[0] as $img_tag)

it works

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜