function strReverse($str) { $rev = ""; $length = strLength($str); for ($i = $length; $i >= 0; $i--) { $rev .= $str[$i]; } return $rev; }
public function add_introduce() { if (IS_POST) { $data = $this->CommonController->getRequestData(); $data = $this->CommonController->arr2ToArr($data['data']); if (!trim($data['dear_hr'])) { $error['msg'] = '必填'; $error['status'] = FALSE; $error['code'] = $this->controller_code + 1; returnjson($error); } if (!strLength($data['dear_hr'], 300)) { $error['msg'] = '限300字内'; $error['status'] = FALSE; $error['code'] = $this->controller_code + 2; returnjson($error); } //对是否存在dearHr进行判断 $student_result = $this->StudentModel->field('dear_hr')->find(session('account.student_id')); $bool = $this->StudentModel->update_introduce($data['dear_hr']); if ($bool) { if (empty($student_result['dear_hr'])) { $stData = array('pkid' => session('account.student_id'), 'complete_rate' => array('exp', 'complete_rate+' . $this->rate_base)); $this->StudentModel->save($stData); } $error['msg'] = '添加成功'; $error['status'] = TRUE; $error['code'] = $this->controller_code + 3; $error['data'] = textareaFormat($this->introduceTpl()); // ; returnjson($error); } else { $error['msg'] = '添加失败'; $error['status'] = FALSE; $error['code'] = $this->controller_code + 4; returnjson($error); } } }
<html> <?php if (isset($_GET['string'])) { $string = $_GET['string']; $result = strLength($string); echo $result; } function strLength($string) { $i = 0; $count = 0; while (isset($string[$i])) { $count = $count + 1; $i++; } return $i; } ?> <body> <form action="own_str_length.php" method="get" align="center"> Given String: <input type="text" name="string"><br><br> <button type="submit">Result</button> </form> </body> </html>
<?php include "own_str_length.php"; $str = "Hello FTFL"; $length = strLength($str); for ($i = $length; $i >= 0; $i--) { echo $str[$i]; }
function setLength($string) { $result = strLength($string); $this->str = $result; return $this->str; }