
如何创建一个会员制网站
wp_extract_urls ( $content )
wp_extract_urls: 这个函数用于从一个给定的字符串中提取所有的URLs。这对于解析包含链接的文本很有用,例如博客文章或评论: 该函数返回一个在输入字符串中发现的URL数组: 这个函数可以用来帮助在WordPress网站内寻找和链接到外部内容的过程自动化。
使用RegEx从任意的内容中提取URLs。
function wp_extract_urls( $content ) { preg_match_all( "#(["']?)(" . '(?:([w-]+:)?//?)' . '[^s()<>]+' . '[.]' . '(?:' . '([wd]+)|' . '(?:' . "[^`!()[]{}:'".,<>«»“”‘’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 ); }