私はこの文字列を持っています:
"small:
http://img.exent.com/free/frg/products/666550/player_boxshot.jpg
boxshot:
http://img.exent.com/free/frg/products/666550/boxshot.jpg"
最初の画像リンク (「小さい」という単語の後) のみを取得し、残りはすべて無視します (「ボックスショット」という単語とその後のリンク)。
どうすれば作れますか?
$string = "small:
http://img.exent.com/free/frg/products/666550/player_boxshot.jpg
boxshot:
http://img.exent.com/free/frg/products/666550/boxshot.jpg";
preg_match_all('~http(.*?)jpg~i',trim($string),$matches);
var_dump($matches[0][0]);
それを使用して、私のansのように。string
上記の文字列全体です
substr(string,0,stripos(string,"boxshot")-1);
これを試して:
$string = "small:
http://img.exent.com/free/frg/products/666550/player_boxshot.jpg
boxshot:
http://img.exent.com/free/frg/products/666550/boxshot.jpg";
// replace all 2 or more consecutive spaces with 1 space
$string = preg_replace( '/\s\s+/i', ' ', $string);
$array = explode( ' ', $string);
echo $array[1];
お役に立てれば。
簡単な方法:
<?php
$str='small: http://img.exent.com/free/frg/products/666550/player_boxshot.jpg boxshot: http://img.exent.com/free/frg/products/666550/boxshot.jpg';
$parts=explode('boxshot:',$str);
$small=$parts[0];
echo($small);
?>