substr

Show 1k instead of 1,000

核能气质少年 提交于 2019-12-10 04:19:00
问题 function restyle_text($input){ $input = number_format($input); $input_count = substr_count($input, ','); if($input_count != '0'){ if($input_count == '1'){ return substr($input, +4).'k'; } else if($input_count == '2'){ return substr($input, +8).'mil'; } else if($input_count == '3'){ return substr($input, +12).'bil'; } else { return; } } else { return $input; } } This is the code I have, I thought it was working. apparently not.. can someone help since I can't figure this out. 回答1: Try this:

PHP生成唯一订单号

烂漫一生 提交于 2019-12-09 20:34:34
在日常的网站开发中,我们经常需要生成唯一的订单号。订单号太短,在高迸发情况下,很容易造成订单号重复事件,虽然是小概率事件。 下面我们使用PHP多个函数生成一个现在最常用的订单号格式: $order_number = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8); 加了毫秒,变成25位了,重复几率更小 $order_number = date('YmdHi'). substr(microtime(), 2, 5) .substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8); 简单从内到外解析一下这个订单号生成过程: date("Ymd"):这个很容易理解,是在最前方拼接一个当前年月日组成的数字 uniqid():此函数获取一个带前缀、基于当前时间微秒数的唯一ID。 substr(uniqid(), 7, 13):由于uniqid()函数生成的结果前面7位很久才会发生变化,所以有或者没有对于我们没有多少影响,所以我们截取后面经常发生变化的几位。 str_split(substr(uniqid(), 7, 13), 1)

How efficient is PHP's substr?

耗尽温柔 提交于 2019-12-08 18:46:47
问题 I'm writing a parser in PHP which must be able to handle large in-memory strings, so this is a somewhat important issue. (ie, please don't "premature optimize" flame me, please) How does the substr function work? Does it make a second copy of the string data in memory, or does it reference the original? Should I worry about calling, for example, $str = substr($str, 1); in a loop? 回答1: To further Chad's comment, your code would require both strings (the full one, and the full-one-minus-first

Create my own strlen and substring functions

99封情书 提交于 2019-12-08 14:20:15
问题 I am trying to create my own strlen and substr functions and I have 1 problem. for example, let say I have the string ABC, my strlen will return 3, let say I want to cut this string from 0 to 1 its should return to me A,but I get some trash values, if I insert the substr to a new char and check the length I will recieve 14. this is my code: int len(char *w){ int count=0; int i=0; while (w[i]!='\0') { count++; i++; } //cout<<"Length of word is:"<<count<<"\n"; return count; } char *subs(char *w

Good Words Gym-101028F

强颜欢笑 提交于 2019-12-08 10:27:52
Good Words Gym-101028F 标签:水题 题目链接 /* 题意:字符串a, b(长度固定为4)。 (1)如果b是a的子串,输出good; (2)否则,若在a中插入一个字符,b是a的子串的话,输出almost good; (3)二者都不行,输出none。 思路:C++函数a.substr(i,4)获得从i开始的长度为4的字串。 almost good: 转化为,枚举出b的四种可能串(去掉一个字符),若a中存在b的可能串,almost good。 */ #include <iostream> #include <string> using namespace std ; string a, b, b1, b2, b3, b4; int main() { int T; cin >> T; while (T--) { cin >> a >> b; int len = a.length(); //注意: for语句内runtime error,可能编译环境不同 int flag = 1 ; for ( int i = 0 ; i < len - 3 ; i++) if (a.substr(i, 4 ) == b) { cout << "good" << endl; flag = 0 ; break ; } if (flag) { b1 = b.substr( 0 , 3 );

Oracle extract variable number from string

旧城冷巷雨未停 提交于 2019-12-08 08:37:11
问题 I'm looking to extract a specific number out of a string of mixed alphanumeric characters that are variable in length in a query. I will need this in order to calculate a range based off that number. I'm using Oracle. Example: D-3-J32P232 -I need to grab the J32 at least, and most likely even the 32 out of that string. This range of numbers can change at any given time. It could range from: D-3-J1P232 to D-3-J322P2342 The numbers after the second and third letters can be any number of length.

substr in awk statement from xml parse

混江龙づ霸主 提交于 2019-12-08 04:11:04
问题 Link to the original question: bash script extract XML data into column format and now for a modification and explanation -> Something within this line of code is not correct and I believe it is with the substr portion and that would be because I don't have a full understanding and would like to learn HOW better to understand it. Yes I have looked at documentation and its not fully clicking. A couple examples as well as an answer would really be helpful. awk -F'[<>]' 'BEGIN{a["STKPR"]="Prod"

Bash substring expansion on array

不打扰是莪最后的温柔 提交于 2019-12-08 02:04:28
问题 I have a set of files with a given suffix. For instance, I have a set of pdf files with suffix .pdf . I would like to obtain the names of the files without the suffix using substring expansion. For a single file I can use: file="test.pdf" echo ${file:0 -4} To do this operation for all files, I now tried: files=( $(ls *.pdf) ) ff=( "${files[@]:0: -4}" ) echo ${ff[@]} I now get an error saying that substring expression < 0 .. ( I would like to avoid using a for loop ) 回答1: Use parameter

Unnecessary quotes adding on sql while executing - codeigniter

天大地大妈咪最大 提交于 2019-12-07 17:25:09
问题 while trying to do a select query I came into a situation where unnecessary quotes are injecting to it on execution. I'm working in Codeigniter. Trying to selects record which having first 4 characters same. Code is: $calendar = $this->db->select("c.first_name as cfn, u.first_name as ufn", false) ->from("{$this->tables['contacts']} c") ->join("{$this->tables['users']} u", " SUBSTR( u.first_name , 1 , 4) = SUBSTR( c.first_name , 1 , 4) ", '') ->where(array('c.status' => 1, 'c.first_name !=' =>