$char = '上海;北京;天津;重庆;香港;澳门;台湾;';function char_jx($char,$delimiter)
{
$char  = rtrim($char,$delimiter);
$element  = explode($delimiter,$char);
$arr[0] = substr_count($char,$delimiter);
$arr[1] = $element;
return $arr;
}
$d = char_jx($char,';');
print_r($d);exit;

解决方案 »

  1.   

    print_r(char_jx("上海;北京;天津;重庆;香港;澳门;台湾;"));function char_jx($char,$regx = "/(.*?);/"){
    preg_match_all($regx, $char, $match);
    return $match[1];
    }
      

  2.   

    用split和join(ASP或JS里的方法,PHP未知,应该有相应方法吧)
      

  3.   

    foolbirdflyfirst(湖水清澈) 的答案不是完全可以了吗? 还有什么疑问?
      

  4.   

    preg_match_all
    手册里有详细的例子
    <?php
    // \\2 是一个逆向引用的例子,其在 PCRE 中的含义是
    // 必须匹配正则表达式本身中第二组括号内的内容,本例中
    // 就是 ([\w]+)。因为字符串在双引号中,所以需要
    // 多加一个反斜线。
    $html = "<b>bold text</b><a href=howdy.html>click me</a>";preg_match_all ("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches);for ($i=0; $i< count($matches[0]); $i++) {
      echo "matched: ".$matches[0][$i]."\n";
      echo "part 1: ".$matches[1][$i]."\n";
      echo "part 2: ".$matches[3][$i]."\n";
      echo "part 3: ".$matches[4][$i]."\n\n";
    }
    ?>
      

  5.   

    需要的关键函数:substr,explode,count
      

  6.   

    谢谢,大家的帮助foolbirdflyfirst(湖水清澈) 的答案最接近,我的要求,谢谢!