【发布时间】:2011-06-10 06:55:21
【问题描述】:
这可能是一个愚蠢的问题,但是如何在 PHP 函数中提取变量的值?我在stackoverflow上找到了如何找到网页标题的代码:
function page_title($url)
{
$fp = file_get_contents($url);
if (!$fp)
return null;
$res = preg_match("/<title>(.*)<\/title>/", $fp, $title_matches);
if (!$res)
return null;
$title = $title_matches[1];
return $title;
}
我在上面的函数之外有一个名为 $extract 的变量,我想将函数中的 $title 的值插入到外部变量 $extract 中。我假设您必须先调用该函数,然后执行其他操作以实现此目的,但我不知道该步骤是什么。
如果我调用函数并且变量 $title 返回值“欢迎来到我的网站”,我想将该值与外部变量 $extract 相关联。
【问题讨论】:
标签: php function variables extract