Post 如何从帖子内容中获取查找链接
我需要一些在html代码中查找链接的帮助Post 如何从帖子内容中获取查找链接,post,Post,我需要一些在html代码中查找链接的帮助 function get_content_link( $content = false, $echo = false ){ if ( $content === false ) $content = get_the_content(); $content = preg_match_all('#[\'"]https?://([^/]+\.)*example.com/[^\'"]*[\'"]#siU', $content,
function get_content_link( $content = false, $echo = false ){
if ( $content === false )
$content = get_the_content();
$content = preg_match_all('#[\'"]https?://([^/]+\.)*example.com/[^\'"]*[\'"]#siU', $content, $links );
$content = $links[1][0];
if ( empty($content) ) {
$content = false;
}
return $content;
}
这恐怕不行。我不知道是什么问题,因为我没有预赛的经验
任何帮助都将不胜感激
谢谢。这就是答案
帮助所有人
function get_Example( $content = false, $echo = false ){
if ( $content === false )
$content = get_the_content();
$regexp = '/href=\"https:\/\/example\.com\/([^\"]*)"/i';
if(preg_match_all($regexp, $content, $link)) {
$content = $link[1][0];
}
if ( empty($content) ) {
$content = false;
}
return $content;
}
变量内容在代码中包含不同的内容:内容本身、链接数量和链接本身。好的做法是只为一件事使用每个变量。或者你会得到无法维护的代码。