如何从3个已知单词中找到一个字符串?

时间:2016-10-07 16:38:43

标签: php html

我从随机的段落字符串中找到一个单词。

setTimeout(function(){bar.animate(0.5)}, 2000);
setTimeout(function(){bar.animate(0.75)}, 2000);
setTimeout(function(){bar.animate(1)}, 2000);

我想找到“http://163.172.67.164/live/chsix/index.mp4?dsgfsdksdfbjdbfsdfsdkfs121413r”。 已知的唯一单词是“mp4”。我可以找到“mp4”位置并找到前后双引号位置吗?有可能吗?

我的一点努力是:

  <head>
<style>
  * {padding-top:10px; margin:0;}
  body {overflow:hidden;}
</style>

<script src="http://content.jwplatform.com/libraries/V6NfEzT7.js"></script>
    </head>
   <center> <body>
<div id="player"></div>
    <script>
        jwplayer('player').setup({
    sources: [{
      file: "rtmp://163.172.67.164:80/live",
      file: "http://163.172.67.164/live/chsix/index.mp4?dsgfsdksdfbjdbfsdfsdkfs121413r"
    }],
    width: "60%",
    aspectratio: "16:9",
    hlshtml: true
  });
</script>
   <!-- Histats.com  (div with counter) --><div id="histats_counter"></div>
  <!-- Histats.com  START  (aync)-->
   <script type="text/javascript">var _Hasync= _Hasync|| [];
  _Hasync.push(['Histats.startgif', '1,3597882,4,10045,"div#histatsC {position: absolute;top:0px;left:0px;}body>div#histatsC {position: fixed;}"']);
  _Hasync.push(['Histats.fasi', '1']);
  _Hasync.push(['Histats.track_hits', '']);
  (function() {
  var hs = document.createElement('script'); hs.type = 'text/javascript';       hs.async = true;
 hs.src = ('//s10.histats.com/js15_gif_as.js');
 (document.getElementsByTagName('head')[0] ||     document.getElementsByTagName('body')[0]).appendChild(hs);
 })();</script>
<noscript><a href="/" alt="" target="_blank" ><div id="histatsC"><img    border="0" src="http://s4is.histats.com/stats/i/3597882.gif?3597882&103"></div></a>

但找到整个双引句是没有意义的。请建议我解决它。

2 个答案:

答案 0 :(得分:0)

这应该有效......请参阅嵌入式评论。 $ z返回您想要的字符串,“163.172.167.164/live/chsix /".

$x = "http://163.172.67.164/live/chsix/index.mp4?dsgfsdksdfbjdbfsdfsdkfs121413r";
$y = parse_url($x);                       //create associative array that can be manipulated$y_exploded = explode('/', $y['path']);   //break the path into an array
array_pop($y_exploded);                   //remove index.mp4
$y_imploded = implode('/', $y_exploded);  //glue the path back together
$z = $y['host'].$y_imploded.'/';

答案 1 :(得分:0)

试试这个:

<?php   
  $link = "http://163.172.67.164/live/chsix/index.mp4?dsgfsdksdfbjdbfsdfsdkfs121413r";
  // Break string on ".mp4" using explode
  $break_first = explode(".mp4", $link );
  // find last slash(/) position from above string
  $last_slash = strrpos($break_first[0],'/');
  $result = substr($break_first[0], 0, $last_slash);
?>