substr
How to subtract 7 days from current date with Moment.js
May be: dateTo = moment().format(‘YYYY-MM-DD’); dateFrom = moment().subtract(7,’d’).format(‘YYYY-MM-DD’); moment#subtract
Delete first 3 characters and last 3 characters from String PHP
Pass a negative value as the length argument (the 3rd argument) to substr(), like: $result = substr($string, 3, -3); So this: <?php $string = “Sean Bright”; $string = substr($string, 3, -3); echo $string; ?> Outputs: n Bri
Using PHP substr() and strip_tags() while retaining formatting and without breaking HTML
Not amazing, but works. function html_cut($text, $max_length) { $tags = array(); $result = “”; $is_open = false; $grab_open = false; $is_close = false; $in_double_quotes = false; $in_single_quotes = false; $tag = “”; $i = 0; $stripped = 0; $stripped_text = strip_tags($text); while ($i < strlen($text) && $stripped < strlen($stripped_text) && $stripped < $max_length) { $symbol … Read more
Extract a substring between two characters in a string PHP
use this code $input = “[modid=256]”; preg_match(‘~=(.*?)]~’, $input, $output); echo $output[1]; // 256 working example http://codepad.viper-7.com/0eD2ns
How to return all except last 2 characters of a string?
You are looking for slice() (also see MDC) id.slice(0, -2)
php substr() function with utf-8 leaves � marks at the end
The comments above are correct so long as you have mbstring enabled on your server. $var = “Бензин Офиси А.С. также производит все типы жира и смазок и их побочных продуктов в его смесительных установках нефти машинного масла в Деринце, Измите, Алиага и Измире. У Компании есть 3 885 станций технического обслуживания, включая сжиженный газ … Read more
Moment JS – how to subtract 7 days from current date?
May be: dateTo = moment().format(‘YYYY-MM-DD’); dateFrom = moment().subtract(7,’d’).format(‘YYYY-MM-DD’); moment#subtract
Ruby – How to select some characters from string
Try foo[0…100], any range will do. Ranges can also go negative. It is well explained in the documentation of Ruby.