How can I get only the key imgurl (https://www.irobot-jp.com/roomba/800series/img/lineup_img_03.png) from the above URL?
I would like to use php for language.
Please let me know the details.
If you want to parse (parse) URLs as strings, you may find explanatory articles with examples if you search around php URL parse, but I think it's normal to combine the parse_url() function with the parse_str() function
$url_string='https://www.google.co.jp/imgres?imgurl=https://www.irobot-jp.com/roomba/800series/img/lineup_img_03.png&imgrefurl=https://www.irobot-jp.com/roomba/800series/&h=294&w=300&tbnid=hii2NgfRdpdAWM:&docid=6SI3d_RhJqENlM&ei=bRXIVvSuNOasmAXEv6H4BQ&tbm=isch';
$query=parse_url($url_string, PHP_URL_QUERY);
parse_str($query,$query_array);
echo$query_array['imgurl'];//->https://www.irobot-jp.com/roomba/800series/img/lineup_img_03.png
<?php
// Target URL
$gs_url="https://www.google.co.jp/imgres?imgurl=https://www.irobot-jp.com/roomba/800series/img/lineup_img_03.png&imgrefurl=https://www.irobot-jp.com/roomba/800series/&h=294&w=300&tbnid=hii2NgfRdpdAWM:&docid=6SI3d_RhJqENlM&ei=bRXIVvSuNOasmAXEv6H4BQ&tbm=isch";
// Regular expression patterns:URLs from imgurl to
$pattern='/.*?imgurl=(http.*?.png|http.*?.jpg|http.*?.jpeg|http.*?.gif).*?/';
preg_match($pattern, $gs_url, $matches, PREG_OFSET_CAPTURE);
echo$matches[1][0];
?>
© 2024 OneMinuteCode. All rights reserved.