Web ページのメタ タグ情報を取得する php スクリプトがあります。このスクリプトは CLI から使用します。私の質問は、引数 (url) を受け取るこのスクリプトにどのように追加し、それをスクリプトに適用するかです。繰り返しますが、これはコマンド ライン インターフェイスからのものです。
これがサンプルスクリプトです。
#!/usr/bin/php
<?php
function getMetaData($url){
// get meta tags
$meta=get_meta_tags($url);
// store page
$page=file_get_contents($url);
// find where the title CONTENT begins
$titleStart=strpos($page,'<title>')+7;
// find how long the title is
$titleLength=strpos($page,'</title>')-$titleStart;
// extract title from $page
$meta['title']=substr($page,$titleStart,$titleLength);
// return array of data
return $meta;
}
// This line should be replaced with the function call using argv
//$tags = getMetaData('$url');
// Check data was passed
if (empty($argv[1])) {
exit("You didn't specify a URL!");
}
// Pass the supplied data into your code
$tags = getMetaData($argv[1]);
echo 'Title: '.$tags['title'];
echo "\n";
echo 'Description: '.$tags['description'];
echo "\n";
echo 'Keywords: '.$tags['keywords'];
?>
助けてくれてありがとう、私はPHPの初心者です。