想要只获得img url
"//lh5.googleusercontent.com/-0qGW989h9DM/AAAAAAAAAAI/AAAAAAAAG3g/aXkL8mbboKY/photo.jpg"
这
<meta itemprop="name" content="Saurabh Sharma">
<meta itemprop="description" content="Works at Google as Product Manager. Lives in San Francisco. Lived in New Delhi - Mumbai - Canonsburg - Pittsburgh - Austin - San Francisco.">
<meta itemprop="image" content="//lh5.googleusercontent.com/-0qGW989h9DM/AAAAAAAAAAI/AAAAAAAAG3g/aXkL8mbboKY/photo.jpg">
<meta itemprop="url" content="https://plus.google.com/+SaurabhSharma">
</head>
<body class="Td lj">
<input type="text" name="hist_state" id="hist_state" style="display:none;">
如何使用preg_match?
答案 0 :(得分:2)
要获取图像内容,请使用以下
$ data = '<meta itemprop="name" content="Saurabh Sharma"><meta itemprop="description" content="Works at Google as Product Manager. Lives in San Francisco. Lived in New Delhi - Mumbai - Canonsburg - Pittsburgh - Austin - San Francisco."><meta itemprop="image" content="//lh5.googleusercontent.com/-0qGW989h9DM/AAAAAAAAAAI/AAAAAAAAG3g/aXkL8mbboKY/photo.jpg"><meta itemprop="url" content="https://plus.google.com/+SaurabhSharma"></head><body class="Td lj"><input type="text" name="hist_state" id="hist_state" style="display:none;">';
preg_match('/<meta itemprop=\"image\" content=\"(.*?)\">/i', $data, $matches);
$ matches将返回一个数组
Array
(
[0] =>
[1] => //lh5.googleusercontent.com/-0qGW989h9DM/AAAAAAAAAAI/AAAAAAAAG3g/aXkL8mbboKY/photo.jpg
)