替换数组的一部分 [英] Replace part of array

查看:86
本文介绍了替换数组的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一些text: <iframe width="853" height="480" src="http://www.youtu....

我知道如何替换width="857" to width="720",但是我的方法是static(substr_replace($source, ''720'', 16, 3)).

如果width="857"在文本中还有其他位置,则我的方法行得通.

在php.net上,我发现-

Hi,

I have some text: <iframe width="853" height="480" src="http://www.youtu....

I know how to replace width="857" to width="720", but my method is static(substr_replace($source, ''720'', 16, 3)).

If width="857" will have some other position in text, my method work horrible.

At php.net I found -

function array_replace_fun($a, $tofind, $toreplace) 
 { 
     $i = array_search($tofind, $a); 
     if ($i === false)
     { 
         return $a;
     } 
     else 
     { 
         $a[$i] = $toreplace; 
         return array_replace($a, $tofind, $toreplace);
     } 
 }



但是功能不起作用.



but function don''t work.

推荐答案

source,``720'',16,3)).

如果width="857"在文本中还有其他位置,则我的方法行得通.

在php.net上,我发现-

source, ''720'', 16, 3)).

If width="857" will have some other position in text, my method work horrible.

At php.net I found -

function array_replace_fun(


a,


要查找,


这篇关于替换数组的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆