Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何返回数组的文本值而不是函数结果?_Php - Fatal编程技术网

Php 如何返回数组的文本值而不是函数结果?

Php 如何返回数组的文本值而不是函数结果?,php,Php,例如,如果我有一个包含一个元素的数组,如下所示: $dom = [file_get_html('https://www.homedepot.com/p/Connecticut-Electric-30-Amp-8-Space-10-Circuits-G2-Manual-Transfer-Switch-Kit-EGS107501G2KIT/100669964', false)]; 如何echo$dom[0]并让它只返回URL(或至少返回文本值),而不是返回函数的结果 多谢各位 代码: 只需将URL

例如,如果我有一个包含一个元素的数组,如下所示:

$dom = [file_get_html('https://www.homedepot.com/p/Connecticut-Electric-30-Amp-8-Space-10-Circuits-G2-Manual-Transfer-Switch-Kit-EGS107501G2KIT/100669964', false)];
如何
echo$dom[0]
并让它只返回URL(或至少返回文本值),而不是返回函数的结果

多谢各位

代码:


只需将URL存储在数组中,然后在需要时执行
文件\u get\u html

$urls = ['https://www.homedepot.com/p/Connecticut-Electric-30-Amp-8-Space-10-Circuits-G2-Manual-Transfer-Switch-Kit-EGS107501G2KIT/100669964',
         'https://www.homedepot.com/p/31180154554',
         'https://www.homedepot.com/p/Connecticut-Electric-30-Amp-Adapts-to-20-Amp-CESMAD3020/100128920'
        ];

foreach($urls as $url)
{
    $dom = file_get_html($url, false);

    if(!$dom->find('span#ajaxPrice', 0))
    {
        echo "<tr><td>" . "Not Listed" . "</td><td>" . $url . "</td><td>" . "Not Listed" . "</td></tr>";
        continue;
    }
    // more code . . .
}
$url=['https://www.homedepot.com/p/Connecticut-Electric-30-Amp-8-Space-10-Circuits-G2-Manual-Transfer-Switch-Kit-EGS107501G2KIT/100669964',
'https://www.homedepot.com/p/31180154554',
'https://www.homedepot.com/p/Connecticut-Electric-30-Amp-Adapts-to-20-Amp-CESMAD3020/100128920'
];
foreach($url作为$url)
{
$dom=file\u get\u html($url,false);
if(!$dom->find('span#ajaxPrice',0))
{
回显“.”未列出“.”$url“.”“未列出“;
继续;
}
//更多代码。
}

只需将URL存储在数组中,然后在需要时执行
文件\u get\u html

$urls = ['https://www.homedepot.com/p/Connecticut-Electric-30-Amp-8-Space-10-Circuits-G2-Manual-Transfer-Switch-Kit-EGS107501G2KIT/100669964',
         'https://www.homedepot.com/p/31180154554',
         'https://www.homedepot.com/p/Connecticut-Electric-30-Amp-Adapts-to-20-Amp-CESMAD3020/100128920'
        ];

foreach($urls as $url)
{
    $dom = file_get_html($url, false);

    if(!$dom->find('span#ajaxPrice', 0))
    {
        echo "<tr><td>" . "Not Listed" . "</td><td>" . $url . "</td><td>" . "Not Listed" . "</td></tr>";
        continue;
    }
    // more code . . .
}
$url=['https://www.homedepot.com/p/Connecticut-Electric-30-Amp-8-Space-10-Circuits-G2-Manual-Transfer-Switch-Kit-EGS107501G2KIT/100669964',
'https://www.homedepot.com/p/31180154554',
'https://www.homedepot.com/p/Connecticut-Electric-30-Amp-Adapts-to-20-Amp-CESMAD3020/100128920'
];
foreach($url作为$url)
{
$dom=file\u get\u html($url,false);
if(!$dom->find('span#ajaxPrice',0))
{
回显“.”未列出“.”$url“.”“未列出“;
继续;
}
//更多代码。
}

删除
文件\u get\u html
?@u\u mulder更可取,但并非绝对必要删除
文件\u get\u html
,否?您需要以不同的方式来处理此问题,并在更高级别上描述您正在尝试执行的操作。@abracadver我正在尝试显示数组[元素]的内容作为字符串而不是函数的求值-当在搜索的URL页面上找不到指定的HTML元素时。请参阅我认为有助于澄清的屏幕截图:通过删除
file\u get\u html
?@u\u mulder更可取,但并非绝对必要删除
file\u get\u html
,否?您需要以不同的方式处理此问题,并在更高级别上描述您正在尝试执行的操作。@abracadver我正在尝试显示数组[元素]的内容作为字符串而不是函数的求值-当在搜索的URL页面上找不到指定的HTML元素时。请看截图,因为我认为它有助于澄清:太好了,这正是我想要的,谢谢!太好了,那正是我想要的,谢谢!