我的字符串看起来像
Temperature is 125或Temperature is 4
字符串始终是相同的格式,即数字始终出现在字符串的末尾.
我需要将这些字符串拆分为数字,所以我将留下两个字符串,例如
string1 = Temperature is
string2 = 125
Run Code Online (Sandbox Code Playgroud)
有什么想法我会怎么做?
我有一个像这样的字符串 -
[ [ -2, 0.5 ],
Run Code Online (Sandbox Code Playgroud)
我想检索数字字符并将它们放入一个最终看起来像这样的数组:
array(
[0] => -2,
[1] => 0.5
)
Run Code Online (Sandbox Code Playgroud)
这样做的最佳方式是什么?
编辑:
一个更彻底的例子
[ [ -2, 0.5, 4, 8.6 ],
[ 5, 0.5, 1, -6.2 ],
[ -2, 3.5, 4, 8.6 ],
[ -2, 0.5, -3, 8.6 ] ]
Run Code Online (Sandbox Code Playgroud)
我逐行浏览这个矩阵,我想将数字提取到每行的数组中.
我有这样的道路
apples/oranges/bananas
Run Code Online (Sandbox Code Playgroud)
我需要在路径中获取中间项,在这种情况下是橙色.
最好的方法是什么?我可以使用strpos和substr自己做,但我想有更好的方法......
我已启用mod_rewrite并使用.htaccess文件传递所有请求index.php.
如果我访问URL的
http://localhost/mysite
http://localhost/mysite/abc
Run Code Online (Sandbox Code Playgroud)
页面加载一次.
但是,如果我在路径中添加额外的部分,页面加载三次,我的css文件不包括在内:
http://localhost/mysite/abc/xyz
http://localhost/mysite/abc/xyz/ttt
Run Code Online (Sandbox Code Playgroud)
等等...
全部导致页面加载三次.我可以看到这一点,因为我index.php在Eclipse中设置了断点.
这是我的.htaccess档案:
<IfModule mod_rewrite.c>
RewriteEngine on
# Block access to "hidden" directories whose names begin with a period.
# Files whose names begin with a period are protected by the FilesMatch directive
# above.
RewriteRule "(^|/)\." - [F]
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize(). …Run Code Online (Sandbox Code Playgroud) 我有类,每个类都有一个与日期相关的成员变量,它总是具有相同的命名格式 - field_{$node->type}_date
例如,如果我的节点类型是'car',则会命名日期字段 field_car_date
所以我循环遍历所有节点,我想访问每个节点的日期相关字段.但是我收到了一个错误.这是代码
$date_field_key = 'field_' . $node->type . '_date';
if (isset($node->$date_field_key['und'][0]['value'])) {
Run Code Online (Sandbox Code Playgroud)
由于第二行,我收到错误.错误是 - Illegal string offset 'und'
与日期相关的变量是一个数组,它有一个带有'und'键的元素.如果我明确写出这一行$node->field_car_date['und'][0]['value']- 它运作正常.就在我动态创建字段名称时,我遇到了这个问题.
对此的任何解决方案,我的语法不正确?