0
4

3 に答える 3

2

まず、フォーマットされていないデータを返す関数が他に存在しないことを確認してください。

そうでない場合は、URL を取得するための簡単で汚い正規表現を次に示します。

$str = '<li><a href="http://foo.com/wp-content/uploads/2011/07/picture.png">picture</a></li>';

preg_match('~\shref="([^"]++)"~', $str, $matches);
$url = $matches[1];
于 2011-07-13T05:59:33.593 に答える
1

ソリューションは次のようになります。

preg_match('@<a href="(.*?)"@i', $your_string_here, $matches);
$the_url = $matches[1];

その他の例: http://php.net/manual/en/function.preg-match.php

于 2011-07-13T05:57:33.733 に答える
1

もっと実践的なことはどうですか?- http://wp-snippets.com/727/custom-display-of-links-blogroll/

    $links = $wpdb->get_results("SELECT * FROM $wpdb->links ORDER BY link_name ASC");
    //start going through all the links and get the required values for each link
    foreach ($links as $link) {
      $linkurl=$link->link_url;
      $linkdesc=$link->link_description;
      $linkname=$link->link_name;
      $linkimage=$link->link_image;
      $linknotes=$link->link_notes; }

WordPress には多くの組み込み関数があります。コードからハッキングしなくても、画像の URL 自体を取得できる可能性があります。

http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

添付ファイルIDがわかっている場合、これはURLを返します

$imgData = wp_get_attachment_image_src( $attachment_id);
echo $imgData[0];
于 2011-07-13T06:16:00.073 に答える