简体   繁体   English

PHP img url with preg_match

[英]PHP img url with preg_match

want to get only the img url 想要只获得img网址

"//lh5.googleusercontent.com/-0qGW989h9DM/AAAAAAAAAAI/AAAAAAAAG3g/aXkL8mbboKY/photo.jpg"

from

    <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;">

how to do it with preg_match ? 如何用preg_match做到这一点?

In order to get image content , use the following 要获取图像内容,请使用以下内容

$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;">'; $ 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 will return an array $ matches将返回一个数组

Array
(
    [0] => 
    [1] => //lh5.googleusercontent.com/-0qGW989h9DM/AAAAAAAAAAI/AAAAAAAAG3g/aXkL8mbboKY/photo.jpg
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM