get_url_in_content

函式
get_url_in_content ( $content )
引數
  • (string) $content A string which might contain a URL.
    Required:
返回值
  • (string|false) The found URL.
定義位置
相關方法
get_the_contentget_user_countget_link_to_editget_media_embedded_in_contentget_blog_count
引入
3.6.0
棄用
-

get_url_in_content: 這個函式檢索出現在文章內容中的第一個URL。它接收一個文章ID作為引數,並以字串形式返回URL。

從傳來的內容中提取並返回第一個URL。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_url_in_content( $content ) {
if ( empty( $content ) ) {
return false;
}
if ( preg_match( '/<as[^>]*?href=(['"])(.+?)1/is', $content, $matches ) ) {
return sanitize_url( $matches[2] );
}
return false;
}
function get_url_in_content( $content ) { if ( empty( $content ) ) { return false; } if ( preg_match( '/<as[^>]*?href=(['"])(.+?)1/is', $content, $matches ) ) { return sanitize_url( $matches[2] ); } return false; }
function get_url_in_content( $content ) {
	if ( empty( $content ) ) {
		return false;
	}

	if ( preg_match( '/<as[^>]*?href=(['"])(.+?)1/is', $content, $matches ) ) {
		return sanitize_url( $matches[2] );
	}

	return false;
}

常見問題

FAQs
檢視更多 >