【问题标题】:preg_match for showing specific url within wordpress contentpreg_match 用于在 wordpress 内容中显示特定的 url
【发布时间】:2014-07-20 07:03:28
【问题描述】:

嗨,我有 wordpress 主题,我想创建音频发布格式,但是当我打电话给 the_content(); 时,给我显示音频播放器和文本内容。但我想在我的帖子中使用preg_match php 函数,直到只显示以.mp3 or .m4a or .ogg 结尾的网址怎么做?

当我以 mu 音频发布格式调用 the_content(); 函数时,我想要的信息不要显示任何图像或任何文本和任何其他 URL。只有我想给我看音频网址。

【问题讨论】:

  • 您的问题对我来说不是很清楚-但您似乎只需要更改主题文件即可。这取决于您的主题,并且很难在这里确定(除非您添加更多信息)

标签: wordpress preg-match


【解决方案1】:

我也解决了我的问题,方法是使用下面的模式仅显示我的 wordpress 帖子内容中的 mp3、ogg、m4a、wav 和 wma 格式

$pattern = "/http:\/\/.*\/(.*)\.(mp3|m4a|ogg|wav|wma)/";
$subject = get_the_content();
preg_match_all ($pattern, $subject, $matches)
echo $matches[0];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 2016-02-04
    • 2016-05-05
    • 1970-01-01
    相关资源
    最近更新 更多