Php 在数组的每个元素中删除http之前的所有内容

Php 在数组的每个元素中删除http之前的所有内容,php,regex,preg-replace,strstr,Php,Regex,Preg Replace,Strstr,我得到了一个数组调用$url,我想为数组中的每个元素删除http之前的所有内容 假设 $urls[1] = hd720\u0026url=http%3A%2F%2Fr2---sn-h50gpup0nuxaxjvh-hg0l.googlevideo.com%2Fvideoplayback%3Fexpire%3D1387559704%26fexp%3D937407%252C908540%252C941239%252C916623%252C909717%252C932295%252C936912%25

我得到了一个数组调用
$url
,我想为数组中的每个元素删除
http
之前的所有内容

假设

$urls[1] = hd720\u0026url=http%3A%2F%2Fr2---sn-h50gpup0nuxaxjvh-hg0l.googlevideo.com%2Fvideoplayback%3Fexpire%3D1387559704%26fexp%3D937407%252C908540%252C941239%252C916623%252C909717%252C932295%252C936912%252C936910%252C923305%252C936913%252C907231%252C907240%252C921090%
我希望是这样

$urls[1] = http%3A%2F%2Fr2---sn-h50gpup0nuxaxjvh-hg0l.googlevideo.com%2Fvideoplayback%3Fexpire%3D1387559704%26fexp%3D937407%252C908540%252C941239%252C916623%252C909717%252C932295%252C936912%252C936910%252C923305%252C936913%252C907231%252C907240%252C921090%
这里我只给出了$URL[1]的示例,但我想删除每个字符,直到找到数组中所有元素的http为止

我试过了

$urls = strstr($urls, 'http');
$urls = preg_replace('.*(?=http://)', '', $urls);
两者都不起作用

与回调函数一起使用:

$urls = array_map(function($url) {
    return preg_replace('~.*(?=http://)~', '$1', urldecode($url));
}, $urls);
与回调函数一起使用:

$urls = array_map(function($url) {
    return preg_replace('~.*(?=http://)~', '$1', urldecode($url));
}, $urls);
与回调函数一起使用:

$urls = array_map(function($url) {
    return preg_replace('~.*(?=http://)~', '$1', urldecode($url));
}, $urls);
与回调函数一起使用:

$urls = array_map(function($url) {
    return preg_replace('~.*(?=http://)~', '$1', urldecode($url));
}, $urls);

与的结合为您提供了预期的结果

$furls = array_map('filterArr',$urls);
function filterArr($v)
{
return urldecode(strstr($v,'http'));
}
print_r($furls);
与之相结合会给您带来预期的结果

$furls = array_map('filterArr',$urls);
function filterArr($v)
{
return urldecode(strstr($v,'http'));
}
print_r($furls);
与之相结合会给您带来预期的结果

$furls = array_map('filterArr',$urls);
function filterArr($v)
{
return urldecode(strstr($v,'http'));
}
print_r($furls);
与之相结合会给您带来预期的结果

$furls = array_map('filterArr',$urls);
function filterArr($v)
{
return urldecode(strstr($v,'http'));
}
print_r($furls);
我会这样做:

foreach($urls as $key=>$val) {
    $e = &$urls[$key]; // notice the &  sign
    // now whatever you do with $e will go back
    // into the original array element
    $e = preg_replace(.............);
} 
我总是使用这种技术来转换数组,因为它既快速又高效。阵列漫游/阵列过滤方式也不错,但当阵列从中到大时,速度要慢得多。

我会这样做:

foreach($urls as $key=>$val) {
    $e = &$urls[$key]; // notice the &  sign
    // now whatever you do with $e will go back
    // into the original array element
    $e = preg_replace(.............);
} 
我总是使用这种技术来转换数组,因为它既快速又高效。阵列漫游/阵列过滤方式也不错,但当阵列从中到大时,速度要慢得多。

我会这样做:

foreach($urls as $key=>$val) {
    $e = &$urls[$key]; // notice the &  sign
    // now whatever you do with $e will go back
    // into the original array element
    $e = preg_replace(.............);
} 
我总是使用这种技术来转换数组,因为它既快速又高效。阵列漫游/阵列过滤方式也不错,但当阵列从中到大时,速度要慢得多。

我会这样做:

foreach($urls as $key=>$val) {
    $e = &$urls[$key]; // notice the &  sign
    // now whatever you do with $e will go back
    // into the original array element
    $e = preg_replace(.............);
} 

我总是使用这种技术来转换数组,因为它既快速又高效。array_walk/array_filter方法也很好,但当您的阵列从中到大时,速度会慢得多。

您可以使用explode在http之前剪切所有内容

       $string = explode("http", $urls);       // Hold the url and cut before the http
       $str = $string[0]; // Hold the first cut - E.G : hd720\u0026url=
       echo $str; // Hold the first cut - E.G : hd720\u0026url=
还要注意,
$string[1]将保留http的另一端:`%3A%2F%2Fr2---sn-h50

所以你可以这样做:

   $str1 = $string[1];
   $fixedUrl =  'http'.$str1; // will hold the fixed http : http%3A%2F%2Fr2---sn-h50gpup0nuxaxjvh-hg0l...

您可以使用explode在http之前剪切所有内容

       $string = explode("http", $urls);       // Hold the url and cut before the http
       $str = $string[0]; // Hold the first cut - E.G : hd720\u0026url=
       echo $str; // Hold the first cut - E.G : hd720\u0026url=
还要注意,
$string[1]将保留http的另一端:`%3A%2F%2Fr2---sn-h50

所以你可以这样做:

   $str1 = $string[1];
   $fixedUrl =  'http'.$str1; // will hold the fixed http : http%3A%2F%2Fr2---sn-h50gpup0nuxaxjvh-hg0l...

您可以使用explode在http之前剪切所有内容

       $string = explode("http", $urls);       // Hold the url and cut before the http
       $str = $string[0]; // Hold the first cut - E.G : hd720\u0026url=
       echo $str; // Hold the first cut - E.G : hd720\u0026url=
还要注意,
$string[1]将保留http的另一端:`%3A%2F%2Fr2---sn-h50

所以你可以这样做:

   $str1 = $string[1];
   $fixedUrl =  'http'.$str1; // will hold the fixed http : http%3A%2F%2Fr2---sn-h50gpup0nuxaxjvh-hg0l...

您可以使用explode在http之前剪切所有内容

       $string = explode("http", $urls);       // Hold the url and cut before the http
       $str = $string[0]; // Hold the first cut - E.G : hd720\u0026url=
       echo $str; // Hold the first cut - E.G : hd720\u0026url=
还要注意,
$string[1]将保留http的另一端:`%3A%2F%2Fr2---sn-h50

所以你可以这样做:

   $str1 = $string[1];
   $fixedUrl =  'http'.$str1; // will hold the fixed http : http%3A%2F%2Fr2---sn-h50gpup0nuxaxjvh-hg0l...

您只是错过了正则表达式周围的分隔符,在数组上运行良好:

$urls = preg_replace('~.*(?=http://)~', '', $urls);
// add delimiters   __^           __^
我使用
~
来避免转义
/
,在这种情况下,它将是:

$urls = preg_replace('/.*(?=http:\/\/)/', '', $urls);
// add delimiters   __^             __^

您只是错过了正则表达式周围的分隔符,在数组上运行良好:

$urls = preg_replace('~.*(?=http://)~', '', $urls);
// add delimiters   __^           __^
我使用
~
来避免转义
/
,在这种情况下,它将是:

$urls = preg_replace('/.*(?=http:\/\/)/', '', $urls);
// add delimiters   __^             __^

您只是错过了正则表达式周围的分隔符,在数组上运行良好:

$urls = preg_replace('~.*(?=http://)~', '', $urls);
// add delimiters   __^           __^
我使用
~
来避免转义
/
,在这种情况下,它将是:

$urls = preg_replace('/.*(?=http:\/\/)/', '', $urls);
// add delimiters   __^             __^

您只是错过了正则表达式周围的分隔符,在数组上运行良好:

$urls = preg_replace('~.*(?=http://)~', '', $urls);
// add delimiters   __^           __^
我使用
~
来避免转义
/
,在这种情况下,它将是:

$urls = preg_replace('/.*(?=http:\/\/)/', '', $urls);
// add delimiters   __^             __^

你从哪里得到这些信息?看起来修复数据源比修复数据源更好。从何处获取此输入?看起来修复数据源比修复数据源更好。从何处获取此输入?看起来修复数据源比修复数据源更好。从何处获取此输入?看起来修复数据源比修复dataEpic dude要好…谢谢much@user2650277很高兴能得到帮助:)@ USER 265077:考虑它是否回答了你的问题。史诗哥们…谢谢much@user2650277很高兴能得到帮助:)@ USER 265077:考虑它是否回答了你的问题。史诗哥们…谢谢much@user2650277: 很高兴能得到帮助:@ USER 265077:考虑它是否回答了你的问题。史诗哥们…谢谢much@user2650277很高兴能得到帮助:)@ USER 265077:考虑它是否回答了你的问题。