0

私はphpが初めてで、何か助けが必要です。この変数から画像とコンテンツを分割する必要があります。画像と説明があります。

$content = "<a href="/pin/211106301253428599/">
<img src="http://media-cache-ak0.pinimg.com/192x/8d/97/f5/8d97f59de2c2d5d8d83fa61f1f4ad7a5.jpg"></a>
No matter where or why you travel, there's always something wonderfully new to be found! <a href="/search?q=quote" class="pintag" title="#quote search Pinterest">#quote</a>";

これは簡単なことだと思いますが、助けてください。変数内の画像と別のリンク付きのコンテンツが必要です..

ありがとう。

4

1 に答える 1

0

@Barmar が言うように、DOM 解析ライブラリを使用する必要があります。

これは非常に便利だと思うかもしれません: http://simplehtmldom.sourceforge.net

その使用法は jQuery の解析に似ており、ドキュメントを読むだけで使用方法を知ることができます (非常に良い例 => http://simplehtmldom.sourceforge.net/manual.htm ) 。

例:

$content = "<a href="/pin/211106301253428599/">
<img src="http://media-cache-ak0.pinimg.com/192x/8d/97/f5/8d97f59de2c2d5d8d83fa61f1f4ad7a5.jpg"></a>
No matter where or why you travel, there's always something wonderfully new to be found! <a href="/search?q=quote" class="pintag" title="#quote search Pinterest">#quote</a>";

$html = str_get_html($content);

$image = $html->find('img');
$links = $html->find('a');

そして、$image と $links で必要なものを手に入れることができます:D

于 2013-08-05T06:05:44.903 に答える