-1

私はこの文字列を持っています:

"small:
http://img.exent.com/free/frg/products/666550/player_boxshot.jpg
boxshot:
http://img.exent.com/free/frg/products/666550/boxshot.jpg"

最初の画像リンク (「小さい」という単語の後) のみを取得し、残りはすべて無視します (「ボックスショット」という単語とその後のリンク)。

どうすれば作れますか?

4

4 に答える 4

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

preg_match_all('~http(.*?)jpg~i',trim($string),$matches);
var_dump($matches[0][0]);
于 2012-04-09T09:16:03.607 に答える
1

それを使用して、私のansのように。string上記の文字列全体です

substr(string,0,stripos(string,"boxshot")-1);
于 2012-04-09T09:11:35.557 に答える
0

これを試して:

$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];

お役に立てれば。

于 2012-04-09T09:31:39.307 に答える
0

簡単な方法:

<?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);
?>
于 2012-04-09T09:16:01.287 に答える