I just started learning regular rules and tried to write one, but an error was reported. My code is:
<?php
$content = file_get_contents('page.html');
$preg='/^<meta property="og:image" content="{1}(.*)" />{1}$/';
if(preg_match($preg,$content,$arr)){
echo $arr[0];
}else{
echo "fail";
}
?>
The purpose is to match <meta property="og:image" content="https://scontent-nrt1-1.cdninstagram.com/t51.2885-15/e35/19428654_117834015492201_3447552780867207168_n.jpg" />The address in
.
Don’t add start and end symbols. If you want to match the content, you shouldn’t add start and end symbols. . . .
Visual inspection is that {1} is wrong
, this is also possible. . But it’s strange, print_r and var_dump produce different results