• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP get_tag_regex函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_tag_regex函数的典型用法代码示例。如果您正苦于以下问题:PHP get_tag_regex函数的具体用法?PHP get_tag_regex怎么用?PHP get_tag_regex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_tag_regex函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: get_media_embedded_in_content

/**
 * Check the content blob for an <audio>, <video> <object>, <embed>, or <iframe>
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain media data.
 * @param array $types array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'
 * @return array A list of found HTML media embeds
 */
function get_media_embedded_in_content($content, $types = null)
{
    $html = array();
    $allowed_media_types = array('audio', 'video', 'object', 'embed', 'iframe');
    if (!empty($types)) {
        if (!is_array($types)) {
            $types = array($types);
        }
        $allowed_media_types = array_intersect($allowed_media_types, $types);
    }
    foreach ($allowed_media_types as $tag) {
        if (preg_match('#' . get_tag_regex($tag) . '#', $content, $matches)) {
            $html[] = $matches[0];
        }
    }
    return $html;
}
开发者ID:dev-lav,项目名称:htdocs,代码行数:26,代码来源:media.php


示例2: get_image_in_content

 /**
  * Extract and return the first image from passed content.
  *
  * @since 3.1.0
  * @link https://core.trac.wordpress.org/browser/trunk/wp-includes/media.php?rev=24240#L2223
  *
  * @param string  $content A string which might contain a URL.
  * @return string The found URL.
  */
 public function get_image_in_content($content)
 {
     $image = '';
     if (!empty($content) && preg_match('#' . get_tag_regex('img') . '#i', $content, $matches) && !empty($matches)) {
         // @todo Sanitize this.
         $image = $matches[0];
     }
     return $image;
 }
开发者ID:TyRichards,项目名称:ty_the_band,代码行数:18,代码来源:class-cedaro-theme-postmedia.php


示例3: img_html_to_post_id

/**
 * Retrieve the attachment post id from HTML containing an image.
 *
 * @since 3.6.0
 *
 * @param string $html The html, possibly with an image
 * @param string $matched_html Passed by reference, will be set to to the matched img string
 * @return int The attachment id if found, or 0.
 */
function img_html_to_post_id($html, &$matched_html = null)
{
    $attachment_id = 0;
    // Look for an <img /> tag
    if (!preg_match('#' . get_tag_regex('img') . '#i', $html, $matches) || empty($matches)) {
        return $attachment_id;
    }
    $matched_html = $matches[0];
    // Look for attributes.
    if (!preg_match_all('#(src|class)=([\'"])(.+?)\\2#is', $matched_html, $matches) || empty($matches)) {
        return $attachment_id;
    }
    $attr = array();
    foreach ($matches[1] as $key => $attribute_name) {
        $attr[$attribute_name] = $matches[3][$key];
    }
    if (!empty($attr['class']) && false !== strpos($attr['class'], 'wp-image-')) {
        if (preg_match('#wp-image-([0-9]+)#i', $attr['class'], $matches)) {
            $attachment_id = absint($matches[1]);
        }
    }
    if (!$attachment_id && !empty($attr['src'])) {
        $attachment_id = attachment_url_to_postid($attr['src']);
    }
    return $attachment_id;
}
开发者ID:jcsilkey,项目名称:CodeReviewSecurityRepo,代码行数:35,代码来源:media.php


示例4: quadro_print_media

/**
 * Store any wanted media for later use and process $content to strip them out of it
 * Argument $types receives an array of wanted media types: 'audio', 'video', 'object', 'embed', or 'iframe'.
 * Function based on get_media_embedded_in_content() from media.php (in Core @since 3.6.0).
 */
function quadro_print_media($content, $types = null, $amount = 999, $before, $after)
{
    $allowed_media_types = array('audio', 'video', 'object', 'embed', 'iframe');
    $media = '';
    $i = 0;
    if (!empty($types)) {
        if (!is_array($types)) {
            $types = array($types);
        }
        $allowed_media_types = array_intersect($allowed_media_types, $types);
    }
    // Filter through the_content filter
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    foreach ($allowed_media_types as $tag) {
        if (preg_match_all('#' . get_tag_regex($tag) . '#', $content, $elements)) {
            foreach ($elements[0] as $element) {
                $media .= $before . $element . $after;
                // Remove element from $content
                $content = str_replace($element, '', $content);
                // Exit this if we reached the requested amount.
                $i++;
                if ($amount == $i) {
                    break 2;
                }
            }
        }
    }
    // Return the results, content and requested media apart
    return array('content' => $content, 'media' => $media);
}
开发者ID:unsognoverde,项目名称:website,代码行数:36,代码来源:extras.php



注:本文中的get_tag_regex函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_tag_template函数代码示例发布时间:2022-05-15
下一篇:
PHP get_tag_link函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap