如何从php中的url字符串中删除引号

时间:2017-10-06 15:32:50

标签: php wordpress

我正在处理使用 video js lib 流式传输视频的wordpress插件,但我无法弄清楚我的代码是如何自动生成的(“和”)我的网址提供给播放器。

这就是谈论的内容,这是文件的网址:

"”https://s3-us-west-2.amazonaws.com/test-past3/data/Andrew+Cranston+-+Banners+of+Progress.mp4″"

这是我的视频播放器代码:

<video class="video-js vjs-skin-flat-red vjs-16-9" id="<?php print $attr['video_id'];?>" style="max-width: 100%;"
          controls
          preload="<?php print $attr['preload']; ?>"
        width="<?php print $width?>"
        <?php print $muted ? "muted" : ""?>
        height="<?php print $height?>" 
        poster="<?php print $attr['poster'];?>"
          data-setup='{
            "plugins": {
              "vastClient": {
                "adTagUrl": "<?php print $attr['adtagurl']; ?>",
                "adCancelTimeout": 5000,
                "adsEnabled": true
                }
              }
            }'>
        <source src="<?php  print $attr['url']; ?>" type="<?php print $mime_type ?>"></source>

        <p class="vjs-no-js">
          To view this video please enable JavaScript, and consider upgrading to a
          web browser that
          <a href="http://videojs.com/html5-video-support/" target="_blank">
            supports HTML5 video
          </a>
        </p>
      </video>

2 个答案:

答案 0 :(得分:2)

只需使用substr()功能:

<source src="<?php print substr($attr['url'], 1, -1); ?>"

但我建议你找出为什么你的$ attr ['url']带引号:)

答案 1 :(得分:0)

另外两个str_replace()preg_replace()的解决方案。

str_replace(['”', '″'], '', $url);
preg_replace('/[”″]+/', '', $url);

此特定情况下substr()更简单,更快(从字符串中删除第一个和最后一个字符)。

substr($url, 1, -1);