function my_preg_match($run = null, $params = null, $i = 0)
{
preg_match($run, $params, $result);
if (!empty($result[0])) {
return $result[$i];
}
else {
echo 'Вхождений не найдено';
}
}
my_preg_match('/(\d)(\d)/','12'); // result 12
my_preg_match('/(\d)(\d)/','12', 1); // result 1
my_preg_match('/(\d)(\d)/','12', 2); // result 2
(\+\d\s\d+\s\d+-\d+-\d+)(.*)(\+\d\s\d+\s\d+-\d+-\d+)(.*)(\+\d\s\d+\s\d+-\d+-\d+)(.*)
\1\n\3\n\5
$file = <<<EOT
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w1920h520mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w225h124mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w280h160mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w600h450mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w730h340mc.jpg
files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg.w820h410mc.jpg
files/9/6/7/b/f/f7ba4cbf32ff8971b352e3fc2ac.jpg
files/9/6/7/b/f/f7ba4cbf32ff8971b352e3fc2ac.jpg.w730h350mc.jpg
files/e/b/1/e/1/05c09ea7a96cf55071450839570.jpg
files/e/b/1/e/1/05c09ea7a96cf55071450839570.jpg.w730h350mc.jpg
files/e/d/2/f/8/7ca3d9a5390be989ca44c8f5d58.jpg
files/e/d/2/f/8/7ca3d9a5390be989ca44c8f5d58.jpg.w730h350mc.jpg
EOT;
preg_match('/^.*?\.jpg/', $file, $m);
echo $m[0]; //files/3/0/b/8/e/267114fe63e7c563b193852ed72.jpg
<a href=".*#popup.*>
<a href="link5.html#id"></a>
$link = "http://vk.com/?utm_content={gbid}%3A{ad_id}&utm_term=term&utm_campaign=campaign&utm_medium=cpc&utm_source=yandex-direct-{source_type}#1";
preg_match('~^(http:\/\/vk.com/).*?(#\d)$~i', '$link', $m);
echo $m[1];
echo $m[2];