标签: substr

Moment JS - 如何从当前日期减去7天?

我想从当前日期减去7天,使用moment.js库获取格式化日期YYYY-MM-DD.

我试着这样做:

    dateTo = moment(new Date()).format('YYYY-MM-DD');
    dateFrom = moment(new Date() - 7).format('YYYY-MM-DD');

   console.log(dateFrom);
   console.log(dateTo);
Run Code Online (Sandbox Code Playgroud)

但是所有返回的值都是相同的.

javascript date substr momentjs

42
推荐指数
3
解决办法
4万
查看次数

使用PHP substr()和strip_tags()同时保留格式并且不破坏HTML

我有各种HTML字符串,可以剪切到100个字符(剥离的内容,而不是原始的),无需剥离标记,也不会破坏HTML.

原始HTML字符串(288个字符):

$content = "<div>With a <span class='spanClass'>span over here</span> and a
<div class='divClass'>nested div over <div class='nestedDivClass'>there</div>
</div> and a lot of other nested <strong><em>texts</em> and tags in the air
<span>everywhere</span>, it's a HTML taggy kind of day.</strong></div>";
Run Code Online (Sandbox Code Playgroud)

标准修剪:修剪到100个字符和HTML中断,剥离的内容达到~40个字符:

$content = substr($content, 0, 100)."..."; /* output:
<div>With a <span class='spanClass'>span over here</span> and a
<div class='divClass'>nested div ove... */
Run Code Online (Sandbox Code Playgroud)

剥离的HTML:输出正确的字符数,但显然会丢失格式:

$content = substr(strip_tags($content)), 0, 100)."..."; /* output:
With a span over here and a nested div …
Run Code Online (Sandbox Code Playgroud)

html php substr strip-tags

41
推荐指数
5
解决办法
3万
查看次数

在字符串PHP中提取两个字符之间的子字符串

是否有一个PHP函数可以提取字符串中2个不同字符之间的短语?像substr();

例:

$String = "[modid=256]";

$First = "=";
$Second = "]";

$id = substr($string, $First, $Second);
Run Code Online (Sandbox Code Playgroud)

因此substr()将是256

任何帮助,将不胜感激 :)

php sql substr

39
推荐指数
2
解决办法
8万
查看次数

提取字符串中的前2个字符

我需要提取字符串中的前2个字符以便稍后创建bin图分布.向量:

x <- c("75 to 79", "80 to 84", "85 to 89") 
Run Code Online (Sandbox Code Playgroud)

我已经走到这一步了:

substrRight <- function(x, n){
  substr(x, nchar(x)-n, nchar(x))
}
Run Code Online (Sandbox Code Playgroud)

调用功能

substrRight(x, 1)
Run Code Online (Sandbox Code Playgroud)

响应

[1] "79" "84" "89"
Run Code Online (Sandbox Code Playgroud)

需要打印最后2个字符而不是第一个字符.

[1] "75" "80" "85"
Run Code Online (Sandbox Code Playgroud)

r substr

27
推荐指数
3
解决办法
5万
查看次数

PHP函数substr()错误

当我使用时,substr()我最后得到一个奇怪的角色

$articleText = substr($articleText,0,500);
Run Code Online (Sandbox Code Playgroud)

我有500个字符的输出和 < -

我怎样才能解决这个问题?这是编码问题吗?我的语言是希腊语.

php substr

24
推荐指数
3
解决办法
2万
查看次数

可以std :: string重载"substr"为rvalue*this并窃取资源吗?

它只是发生在我身上,我注意到std::stringsubstr操作可能是右值更有效时,它可以盗取分配的内存*this.

N3225的标准库包含以下成员函数声明 std::string

basic_string substr(size_type pos = 0, size_type n = npos) const;
Run Code Online (Sandbox Code Playgroud)

可以实现substr针对rvalues 优化的实现是否会重载并提供两个版本,其中一个版本可以为rvalue字符串重用缓冲区?

basic_string substr(size_type pos = 0) &&;
basic_string substr(size_type pos, size_type n) const;
Run Code Online (Sandbox Code Playgroud)

我想rvalue版本可以实现如下,*this将设置的内存*this重用于移动状态.

basic_string substr(size_type pos = 0) && {
  basic_string __r;
  __r.__internal_share_buf(pos, __start + pos, __size - pos);
  __start = 0; // or whatever the 'empty' state is
  return __r;
}
Run Code Online (Sandbox Code Playgroud)

这是否在常见的字符串实现上以有效的方式工作,还是会占用过多的内务管理?

c++ substr rvalue-reference c++11

21
推荐指数
1
解决办法
1682
查看次数

模板中的Django substr/substring

有人能告诉我,在Django模板中是否存在类似PHP中的substr(http://pl2.php.net/manual/en/function.substr.php)的方法?

python django templates substr

21
推荐指数
3
解决办法
2万
查看次数

PHP substr但保留HTML标签?

我想知道是否有一种优雅的方式来修剪一些文本但是在识别HTML标签的同时?

例如,我有这个字符串:

$data = '<strong>some title text here that could get very long</strong>';
Run Code Online (Sandbox Code Playgroud)

并且假设我需要在页面上返回/输出此字符串,但希望它不超过X个字符.让我们说35这个例子.

然后我用:

$output = substr($data,0,20);
Run Code Online (Sandbox Code Playgroud)

但现在我最终得到:

<strong>some title text here that 
Run Code Online (Sandbox Code Playgroud)

正如您所看到的那样,关闭强标签将被丢弃,从而打破HTML显示.

有没有解决的办法?另请注意,可以在字符串中包含多个标记,例如:

<p>some text here <strong>and here</strong></p>
Run Code Online (Sandbox Code Playgroud)

php substr

20
推荐指数
2
解决办法
1万
查看次数

最后的特殊字符的php substr结果是questionmark

当我在PHP中使用的SUBSTR()函数,我得到一个问号(带有问号方 - 视浏览器)在字符串的结尾,当这最后一个字符是一个特殊的一个,像E或O等...

$introtext = html_entity_decode($item->description, ENT_QUOTES, "UTF-8");
$introtext = substr($introtext, 0, 200);
Run Code Online (Sandbox Code Playgroud)

我该怎么逃避这个?提前致谢!

php joomla substr

18
推荐指数
4
解决办法
1万
查看次数

如何从mysql数据库字段中检索最后4个字符?

为了能够从PHP和mysql模拟substr,我想做类似的事情

select * from table where last_four_chars(field) = '.png'
Run Code Online (Sandbox Code Playgroud)

php mysql substr

17
推荐指数
3
解决办法
3万
查看次数

标签 统计

substr ×10

php ×6

c++ ×1

c++11 ×1

date ×1

django ×1

html ×1

javascript ×1

joomla ×1

momentjs ×1

mysql ×1

python ×1

r ×1

rvalue-reference ×1

sql ×1

strip-tags ×1

templates ×1