Question

want to get only the img url

"//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 ?

Was it helpful?

Solution

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

preg_match('/<meta itemprop=\"image\" content=\"(.*?)\">/i', $data, $matches);

$matches will return an array

Array
(
    [0] => 
    [1] => //lh5.googleusercontent.com/-0qGW989h9DM/AAAAAAAAAAI/AAAAAAAAG3g/aXkL8mbboKY/photo.jpg
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top