如何计算codeigniter中的段总数?

I want to count total number of segments in codeigniter so I can display error if user/visitor enter additional segment in my url.

Have you checked the manual yet? There is such method that will get the total segments. $this->uri->total_segments()

Or also you can use $this->uri->segment_array().

$total = count($this->uri->segment_array());