【问题标题】:How to remove the string href from the following associative array?如何从以下关联数组中删除字符串 href?
【发布时间】:2015-03-12 10:16:36
【问题描述】:

我关注了标题为$arr的数组:

Array(
    [0] => Array
        (
[url] =>  href="http://52.1.47.143/file/attachment/2015/03/a4ea5532b83a56bbbae2fffc80de4fee.png"
        )
[1] => Array
        (
[url] =>  href="http://52.1.47.143/feed/download/year_2015/month_03/file_1b87d4420c693f2bbdf738cbf2457d89.pdf"        )
) 

我不想在我想要的内容中包含字符串href:

Array(
    [0] => Array
        (
[url] =>  http://52.1.47.143/file/attachment/2015/03/a4ea5532b83a56bbbae2fffc80de4fee.png
        )
[1] => Array
        (
[url] =>  http://52.1.47.143/feed/download/year_2015/month_03/file_1b87d4420c693f2bbdf738cbf2457d89.pdf        )
) 

我该怎么做?

【问题讨论】:

  • 为什么不用str_replace来替换字符串..
  • 迭代数组,获取和替换值。将它们存储回数组。
  • @phpfresher:好的,我删除了 href 字符串。如何去掉 URL 字符串周围的双引号?
  • 你可以在str_replace中使用一个数组...试试这个..str_replace(array('href=','"'),'',$str)

标签: php arrays string multidimensional-array associative-array


【解决方案1】:

试试这个:

foreach ($array as $str) {
    $str = str_replace('href=','',$str);
}

编辑:

您可以在str_replace() 函数中使用数组。像这样:

foreach ($array as $str) {
    $str = str_replace(array('href=','"'),'',$str);
}

【讨论】:

  • 如何去掉 URL 字符串周围的双引号?
猜你喜欢
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多