Uti Mac
Uti Mac

Reputation: 61

How do i remove quotes from url string in php

I'm working on a wordpress plugin that streams videos using video js lib, but i can't figure out how my code automatically generates this (” and ″) in all my url supplied to the player.

this is what talking about, this is the url of the file :

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

this is my video player code:

<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>

Upvotes: 1

Views: 353

Answers (2)

Wixty
Wixty

Reputation: 25

Another two solutions with str_replace() and preg_replace().

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

But substr() is simpler and faster in this specific case (remove first and last characters from string).

substr($url, 1, -1);

Upvotes: 0

Paul
Paul

Reputation: 380

Just use the substr() function :

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

But i recommand you to find why your $attr['url'] come with quotes :)

Upvotes: 2

Related Questions