gpt4 book ai didi

PHP 非法偏移类型

转载 作者:IT王子 更新时间:2023-10-29 00:10:38 26 4
gpt4 key购买 nike

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
}

有人吗?我要为此撕破我的头发......

这是我的 $img_tag 的 var_dump

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

最佳答案

假设 $img_tag 是某种类型的对象,而不是适当的字符串,将 $img_tag 转换为 [] 中的字符串

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

一些对象类型,例如SimpleXMLElement,将通过magic method __toString() 将字符串表示形式返回给print/echo。 , 但不能作为常规字符串出现。尝试将它们用作数组键将产生 illegal offset type 错误,除非您通过 (string)$obj 将它们转换为正确的字符串。

关于PHP 非法偏移类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7732109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com