私のコードでは、preg_match()関数を使用して文字列からURLを抽出しようとしていますが、正しく機能していません。ここでPHP preg_matchが完全に動作しない
は、文字列の例である
FileID = "http://downloader.example.com/myfile/Josh.mp4";
私の期待
http://downloader.example.com/myfile/Josh.mp4
ここに私のPHPコードは次のように
<?php
$stringURL = "FileID = \"http://downloader.example.com/myfile/Josh.mp4\";";
preg_match('/FileID(.*)=(.*)"(.*)"/U', $stringURL,$matches);
if (isset($matches[0])) {
$myurl = $matches[0];
} else {
$myurl = "http://";
}
echo $myurl;
?>
'$ myurl = $ matches [3];'を試してください。 – brevis
または 'print_r($ matches)'と正しいキーを見つけてください。 –