- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以...所有属性都已完美排序
但是
如何将它们替换(/合并)回原来的 $css 值?
这段代码几乎是不言自明的,但我已经添加了我期望得到的内容以防万一……这里需要进行一些小调整:)
<?php
function mySort($arr) {
$arr = explode( ";" , $arr);
sort($arr);
array_shift($arr);
$returnMe = NULL;
foreach ($arr as $key) {
$returnMe .= $key.';';
}
unset($arr);
return $returnMe."\r\n";
}
$css = <<<EOF
body {
z-index:9;
padding:0;
margin:0;
line-height:10px;
}
p {
z-index: 9;
font-size: 10px;
}
h1,h2,h3,h4,h5,h6 {
z-index: 2;
padding: 0;
margin: 0;
font-size: 100%;
border: 0 none;
}
EOF;
echo '<pre>'.
preg_replace_callback( '~.*?{(.*?)}~s',
function ($match) {
return mySort( $match[1] );
}
,$css )
.'</pre>';
我希望得到:
body {
line-height:10px;
margin:0;
padding:0;
z-index:9;
}
p {
font-size: 10px;
z-index: 9;
}
h1,h2,h3,h4,h5,h6 {
border: 0 none;
font-size: 100%;
margin: 0;
padding: 0;
z-index: 2;
}
最佳答案
您正在匹配 CSS 选择器,但并未将其添加回返回值 - 它只是被回调函数替换
所以您需要做的是也捕获这些部分,并从回调中返回它们,如下所示:
echo '<pre>'.
preg_replace_callback( '~(.*?{)(.*?)(})~s', function ($match) {
return $match[1] . mySort( $match[2] ) . $match[3];
}
,$css )
.'</pre>';
关于php - 使用 preg_replace_callback 对属性进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22571666/
我在文本中有几个“短代码” block ,我想使用 preg_replace_callback 将它们替换为一些 HTML 实体。 短代码的语法很简单: [block:type-of-the-bloc
我有一个正则表达式的问题。 我正在使用 token ,我必须解析这样的文本: Just some random text #IT=AB|First statement# #xxxx=xxx|First
我有这个代码: $string = 'The quick brown fox jumped over the lazy dog and lived to tell about it to his cr
我有正则表达式来查找所有带百分比的数字 (100|\d\d|\d)\% - 此正则表达式已给出,我不能更改它。我有输入字符串: Lorem ipsum 10% dolor, 8%sit amet 50
今天我开始理解具有已知值的 preg_replace_callback,得到了一些很大的帮助。但现在我想处理未知的值。 $string = ' texttextmore textPage 6Page
我使用 Wordpress 插件 Codecolorer ( https://wordpress.org/plugins/codecolorer/ ),在 PHP 7 上我遇到了这个问题: /**
我有以下 HTML 语句 [otsection]Wallpapers[/otsection] WALLPAPERS GO HERE [otsection]Videos[/otsection] VIDE
我刚刚将服务器上的PHP从php 5更新到了php 7,并且收到以下警告: 警告:preg_replace_callback()[function.preg-replace-callback0]:要求
使用 PHP preg_replace_callback函数,我想用子字符串“X1X2”替换模式“function([x1,x2])”的出现,用子字符串“X1X2X3”替换“function([x1,
这个问题已经有答案了: Are PHP Variables passed by value or by reference? (16 个回答) 已关闭 8 年前。 我有一个看起来像这样的函数... f
有没有一种简单的方法来跟踪 preg_replace_callback 中的当前索引?我需要替换以下内容,例如: {get}50{end get} 使用 $someArray[50] 的值。我不能只将
我有一个问题要问你! 通常,如果您在 OOP 上下文中调用回调函数,则必须使用 array(&$this, 'callback_function') 这就是我想出来的。 但现在我想在外部类中调用回调,
这个问题已经有答案了: Are PHP Variables passed by value or by reference? (16 个回答) 已关闭 8 年前。 我有一个看起来像这样的函数... f
我正在尝试将使用 javascript 替换函数的 javascript 翻译成 PHP。 js 替换有一个使用偏移量和源字符串值的回调。我尝试使用 preg_replace_callback js
我正在尝试创建一个网络应用程序,它将任何选定的网页转换为简单的英语形式。我有一个逐字翻译存储在 MySQL 数据库中。到目前为止我有这个代码。它有效,但似乎只能在几个标签中完成我想要的操作,而不是整个
我有一个 JavaScript 函数(不是普通的 JavaScript) function formatString () { var args = jQuery.makeArray(argu
所以...所有属性都已完美排序 但是 如何将它们替换(/合并)回原来的 $css 值? 这段代码几乎是不言自明的,但我已经添加了我期望得到的内容以防万一……这里需要进行一些小调整:) '. p
我在一些使用旧系统的页面上有链接,例如: This is a link 他们需要转换到新系统,例如: This is a link 我可以使用 preg_replace t0 更改一些我需要的内容,但
我正在尝试创建一个 REGEX 输入 > quote the rest of it > another paragraph the rest of it 和OUTPUT quotethe rest o
我正在尝试用传递的数组中的值替换 $text 中的 {{key}} 项。但是当我尝试添加 print_r 以查看发生了什么时,我收到了 Undefined variable: kvPairs 错误。如
我是一名优秀的程序员,十分优秀!