【问题标题】:how to replace video code with html code using php如何使用 php 将视频代码替换为 html 代码
【发布时间】:2014-06-27 00:00:58
【问题描述】:

我想用php替换一些html标签

我的字符串是:

some contents are before tags
<div class="videoPlayerCont">
    <div id="myElement">please wait...</div>
</div>
<script type="text/javascript">

        jwplayer("myElement").setup({
            file: "http://mydomain.com/video/20140623.mp4",
            image: "",
            width: 500
        });
</script>
and some contents is after tags

现在我想要:

some contents are before tags
[video]http://mydomain.com/video/20140623.mp4[/video]
and some contents is after tags

请帮助我。 我不知道怎么用preg_replace

【问题讨论】:

  • A.你为什么使用preg_replace? B. 你自己尝试过吗?
  • 这是从哪里来的?你想做什么(从更广泛的角度来看)?大多数人反其道而行之.. 想用 html 替换一个 bbcode 样式标签 ..
  • 我无法使用preg_replace
  • 我认为你过于复杂了。你为什么这样做?你想要的最终结果是什么?这看起来可以用 JavaScript 完全解决,但如果不知道更多关于你在做什么,就很难确定。
  • 如果您想搜索 html 并替换为 bbcode style 字符串,那么您应该使用像 php.net/DOM 这样的 DOM Parser。

标签: php html tags preg-replace


【解决方案1】:

我不明白您为什么要这样做,但无论如何...您可以使用phpQuery 安全轻松地解析 HTML 代码:

  1. 检查类videoPlayerCont的div是否存在
  2. 如果是,则使用text方法获取相邻script元素的内容
  3. 用正则表达式搜索提取的JS代码,找到第一个URL

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 2023-03-23
    • 2013-10-24
    相关资源
    最近更新 更多