请教如何一个将php函数转为.net方法
function showdistrict($values, $elems=array(), $container='districtbox', $showlevel=null, $containertype = 'birth') {
$html = '';
if(!preg_match("/^[A-Za-z0-9_]+$/", $container)) {
return $html;
}
$showlevel = !empty($showlevel) ? intval($showlevel) : count($values);
$showlevel = $showlevel <= 4 ? $showlevel : 4;
$upids = array(0);
for($i=0;$i<$showlevel;$i++) {
if(!empty($values[$i])) {
$upids[] = intval($values[$i]);
} else {
for($j=$i; $j<$showlevel; $j++) {
$values[$j] = '';
}
break;
}
}
$options = array(1=>array(), 2=>array(), 3=>array(), 4=>array());
if($upids && is_array($upids)) {
foreach(C::t('common_district')->fetch_all_by_upid($upids, 'displayorder', 'ASC') as $value) {
if($value['level'] == 1 && ($value['id'] != $values[0] && ($value['usetype'] == 0 || !(($containertype == 'birth' && in_array($value['usetype'], array(1, 3))) || ($containertype != 'birth' && in_array($value['usetype'], array(2, 3))))))) {
continue;
}
$options[$value['level']][] = array($value['id'], $value['name']);
}
}
$names = array('province', 'city', 'district', 'community');
for($i=0; $i<4;$i++) {
if(!empty($elems[$i])) {
$elems[$i] = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\]]/", '', $elems[$i]));
} else {
$elems[$i] = ($containertype == 'birth' ? 'birth' : 'reside').$names[$i];
}
}
for($i=0;$i<$showlevel;$i++) {
$level = $i+1;
if(!empty($options[$level])) {
$jscall = "showdistrict('$container', ['$elems[0]', '$elems[1]', '$elems[2]', '$elems[3]'], $showlevel, $level, '$containertype')";
$html .= '<select name="'.$elems[$i].'" id="'.$elems[$i].'" class="ps" onchange="'.$jscall.'" tabindex="1">';
$html .= '<option value="">'.lang('spacecp', 'district_level_'.$level).'</option>';
foreach($options[$level] as $option) {
$selected = $option[0] == $values[$i] ? ' selected="selected"' : '';
$html .= '<option did="'.$option[0].'" value="'.$option[1].'"'.$selected.'>'.$option[1].'</option>';
}
$html .= '</select>';
$html .= ' ';
}
}
return $html;
}
class table_common_district extends discuz_table
{
public function __construct() {
$this->_table = 'common_district';
$this->_pk = 'id';
parent::__construct();
}
public function fetch_all_by_upid($upid, $order = null, $sort = 'DESC') {
$upid = is_array($upid) ? array_map('intval', (array)$upid) : dintval($upid);
if($upid !== null) {
$ordersql = $order !== null && !empty($order) ? ' ORDER BY '.DB::order($order, $sort) : '';
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('upid', $upid)." $ordersql", array($this->_table), $this->_pk);
}
return array();
}
public function fetch_all_by_name($name) {
if(!empty($name)) {
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('name', $name), array($this->_table));
}
return array();
}
}
public function fetch_all() {
return DB::fetch_all('SELECT * FROM %t', array($this->_table));
}
...全文
相关推荐
在C#中生成与PHP一样的MD5 Hash Code的方法
主要介绍了如何在C#中生成与PHP一样的MD5 Hash Code,需要的朋友可以参考下
PHP实现json_decode不转义中文的方法
主要介绍了PHP实现json_decode不转义中文的方法,结合实例形式具体分析了php5.4+及5.3版本针对json_decode实现不转义中文的具体操作技巧与相关注意事项,需要的朋友可以参考下
PHP获取网页标题的3种实现方法代码实例
一、推荐方法 CURL获取 <?php$c = curl_init();$url = ‘www.jb51.net’;curl_setopt($c, CURLOPT_URL, $url);curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);$data = curl_exec($c);curl_close($c);$pos = strpos($data,’utf-8′);if($pos===false){$data = iconv(“gbk”,”utf-8″,$data);}preg_match(“/<title>(.*)<\/title>/i”,$data, $
PHP 页面跳转到另一个页面的多种方法方法总结
如何在PHP中从一个页面重定向到另外一个页面呢?这里列出了三种办法,供参考。
PHP和.net中des加解密的实现方法
PHP和.net中des加解密的实现方法,需要的朋友可以参考一下


