strlen

strlen() and UTF-8 encoding

一笑奈何 提交于 2019-12-17 16:08:00
问题 Assuming UTF-8 encoding, and strlen() in PHP, is it possible that this string has a length of 4? I'm only interested to know about strlen(), not other functions This is the string: $1�2 I have tested it on my own computer, and I have verified UTF-8 encoding, and the answer I get is 6. I don't see anything in the manual for strlen or anything I've read on UTF-8 that would explain why some of the characters above would count for less than one. PS: This question and answer (4) comes from a

php截取字符串几个实用的函数

最后都变了- 提交于 2019-12-16 13:08:48
本文转载自: https://www.cnblogs.com/xzj8023tp/p/6430944.html 作者:xzj8023tp 转载请注明该声明。 1.substr(源字符串,其实位置[,长度])-截取字符串返回部分字符串 <? php $str = "phpddt.com" ; echo substr ( $str , 2 ); //pddt.com echo substr ( $str , 2 , 3 ); //pdd echo substr ( $str , - 2 ); //om 负数从结尾开始取 ?> 但是当你截取中文字符串的时候很容易出现乱码,因为一个汉字是两个字节,而一个英文字母是一个字节。解决办法如下: 2.mb_substr(),使用方法和substr相同,不过要开启php.ini里面extension=php_mbstring.dll扩展,不用担心,一般的空间商 都会开启这个扩展的。 <? php echo mb_substr ( "php点点通" , 1 , 3 , "UTF-8" ); //hp点 ?> 代码如下: substr(string,start,length) 其中start的参数 正数 - 在字符串的指定位置开始 负数 - 在从字符串结尾的指定位置开始 0 - 在字符串中的第一个字符处开始 ***********************

php将金额数字转化为中文大写

余生颓废 提交于 2019-12-16 08:03:37
php将金额数字转化为中文大写 /** * Undocumented function *数字金额转换成中文大写金额的函数 *String Int $num 要转换的小写数字或小写字符串 *return 大写字母 *小数位为两位 **/ function num_to_rmb ( $num ) { $c1 = "零壹贰叁肆伍陆柒捌玖" ; $c2 = "分角元拾佰仟万拾佰仟亿" ; //精确到分后面就不要了,所以只留两个小数位 $num = round ( $num , 2 ) ; //将数字转化为整数 $num = $num * 100 ; if ( strlen ( $num ) > 10 ) { return "金额太大,请检查" ; } $i = 0 ; $c = "" ; while ( 1 ) { if ( $i == 0 ) { //获取最后一位数字 $n = substr ( $num , strlen ( $num ) - 1 , 1 ) ; } else { $n = $num % 10 ; } //每次将最后一位数字转化为中文 $p1 = substr ( $c1 , 3 * $n , 3 ) ; $p2 = substr ( $c2 , 3 * $i , 3 ) ; if ( $n != '0' || ( $n == '0' && ( $p2 == '亿'

What is strlen elision?

流过昼夜 提交于 2019-12-14 03:52:34
问题 I can see it listed as one of the modern C++ idioms, but what it is exactly? Is it just a type of copy elision? 回答1: You might know that std::strlen loops over the whole string. This can be inefficient in some cases, as it means that the CPU has to start counting characters, which reduces cache locality for other stuff. But in most cases, the compiler is able to optimize std::strlen and count the number of characters of the string itself instead of making the resulting program do it. This is

PHP strlen(str) not working

时光毁灭记忆、已成空白 提交于 2019-12-14 03:33:56
问题 I have a form on my website that takes input from a text area and processes it one way if it is empty (strlen = 0) and another if it has text in it. Here is part of the form: <form name='contact' action='contact.php' method='post'> ... Message*<br /> <textarea name='msg' rows='10' cols='70' maxlength='2048'><?php echo $msg ?></textarea><br /> ... <input type='submit' value='Send!' id='subby' name='fatk' style='height:60px; width:300px;' /> </form> Now the PHP code: $msg = isset($_POST['msg'])

using strlen to find length of user input c [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-13 23:30:41
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I am trying to create an array that to store a user's input, and I need the array to be the exact length of the user's input. I would like to take the length of the user's input, and use this as the length of the array. How can I do this with strlen? Is there any better way? 回答1: This is one way to

Strlen gives an incorrect output after fgets

烈酒焚心 提交于 2019-12-13 11:12:51
问题 I read a string using fgets. It prints correctly but if i try to output the length using a strlen or a while until NULL it returns a bad value. Does fgets not end the string with NULL? char word[256]; fgets(word, sizeof(word), stdin); while(word[i]) i++; printf("%d",i); For the string aba it outputs 40. 回答1: Function fgets also includes the new line character in the string. So function strlen counts this symbol. From the C Standard 2 The fgets function reads at most one less than the number

Strlen is not giving correct output

与世无争的帅哥 提交于 2019-12-13 10:34:10
问题 I have a string which I retrieve from a database, I want to calculate the length of the string without spaces but it is displaying a larger value of length(21 characters greater than the actual count) I have removed tab and newline characters and also the php and html tags but no result! I have tried almost every function on the w3schools php reference but I'm unable to find any success. I also have observed that if I don't retrieve the value from the database and input it like this: $string

php websocket实现网页聊天室

陌路散爱 提交于 2019-12-13 01:45:46
chat.html: <!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/> <title>HTML5 websocket 网页聊天室 javascript php</title> <style type="text/css"> body,p{margin:0px; padding:0px; font-size:14px; color:#333; font-family:Arial, Helvetica, sans-serif;} #ltian,.rin{width:98%; margin:5px auto;} #ltian{border:1px #ccc solid;overflow-y:auto; overflow-x:hidden; position:relative;} #ct{margin-right:111px; height:100%;overflow-y:auto;overflow-x: hidden;} #us{width:110px; overflow-y:auto; overflow-x:hidden; float:right;

strlen gives larger number than the size of an array

半腔热情 提交于 2019-12-12 19:17:39
问题 This might be trivial and I hope someone could explain this. Why strlen is giving me larger number than this real size of char array instead of 4: Here is my code: #include <stdio.h> #include <string.h> int main () { char szInput[4]; szInput [0] = '1'; szInput [1] = '1'; szInput [2] = '1'; szInput [3] = '1'; printf ("The sentence entered is %u characters long.\n",(unsigned)strlen(szInput)); return 0; } I thought I should be getting 4 as the output but I am getting 6. The sentence entered is 6