функция
since 3.7.0
wp_extract_urls()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_extract_urls( string $content ): string[]
Описание
Использует регулярные выражения для извлечения URL из произвольного содержимого.
Параметры
$content
string
обязательный
Содержимое, из которого нужно извлечь URL.
Возвращаемое значение
string[]
Исходный код
wp-includes/functions.php:836
function wp_extract_urls( $content ) {
preg_match_all(
"#([\"']?)("
. '(?:([\w-]+:)?//?)'
. '[^\s()<>]+'
. '[.]'
. '(?:'
. '\([\w\d]+\)|'
. '(?:'
. "[^`!()\[\]{}:'\".,<>«»“”‘’\s]|"
. '(?:[:]\d+)?/?'
. ')+'
. ')'
. ")\\1#",
$content,
$post_links
);
$post_links = array_unique(
array_map(
static function ( $link ) {
// Decode to replace valid entities, like &.
$link = html_entity_decode( $link );
// Maintain backward compatibility by removing extraneous semi-colons (`;`).
return str_replace( ';', '', $link );
},
$post_links[2]
)
);
return array_values( $post_links );
}
История изменений
| Версия | Описание |
|---|---|
| 6.0.0 | Fixes support for HTML entities (Trac 30580). |
| 3.7.0 | Introduced. |

