-2

我有一个这样的字符串[tubelist dijfisj, ijdsifjad, ajkdfksd, sdjfkdf],我想将它们分成两个###URL######URL2###.

这是我到目前为止得到的代码

function xyz_plugin_callback($match)
{
  $tag_parts = explode(",", rtrim($match[0], "]"));
  $output = YOUX_TARGET;
  $output = str_replace("###URL###", $tag_parts[1], $output);
  $output = str_replace("###URL2###", $tag_parts[2], $output);
}

$match是我传入的变量。

4

2 回答 2

0

最后,我让它工作了!这是工作代码。

$tag_parts1 = explode(" ", rtrim($match[0], "]"));

$tag_parts = explode(",",$tag_parts1[1],2);

第一行将剥离 [tubelist 和 ]。第二行将第一组值存储在数组 [0] 中,其余的值存储到 [1]。

瞧,案件已解决。

于 2012-09-15T22:23:38.850 回答
0

您可以在此处使用正则表达式。

因此,如果您执行以下操作:

$temp_match = trim($match[0], "[]");

$urls = array();
preg_match("/([\w\s]*),([\w\s]*),.*/", $temp_match, $urls);

$url1 = $urls[1];
$url2 = $urls[2];

// do your $output str_replace here.
于 2012-09-13T06:00:33.607 回答