一般的捕获组可以用 \0 \1 \N 来表名,如果是用 P
<code> <?php $text="<span style='some' > AAAA "; $text.="<img style="max-width:90%" alt="preg_replace中在替换参数怎么引用命名捕获组?" >"; $text.="<p style="some">"; $text.="<img style="max-width:90%" alt="preg_replace中在替换参数怎么引用命名捕获组?" >"; $text.="</p> <p style="some"> some </p>"; $out=preg_replace("/span|p)[^>]+>(.+))>/","[\P= TAG]\\1[\/\k<tag>]",$text); print_r( $out);</tag></code>
好象直接用k
回复内容:
一般的捕获组可以用 \0 \1 \N 来表名,如果是用 P
<code> <?php $text="<span style='some' > AAAA "; $text.="<img style="max-width:90%" alt="preg_replace中在替换参数怎么引用命名捕获组?" >"; $text.="<p style="some">"; $text.="<img style="max-width:90%" alt="preg_replace中在替换参数怎么引用命名捕获组?" >"; $text.="</p> <p style="some"> some </p>"; $out=preg_replace("/span|p)[^>]+>(.+))>/","[\P= TAG]\\1[\/\k<tag>]",$text); print_r( $out);</tag></code>
好象直接用k
http://php.net/manual/en/function.preg-replace.php
replacement may contain references of the form \n or (since PHP
4.0.4) $n, with the latter form being the preferred one. Every such reference will be replaced by the text captured by the n'th
parenthesized pattern. n can be from 0 to 99, and \0 or $0 refers to
the text matched by the whole pattern. Opening parentheses are counted
from left to right (starting from 1) to obtain the number of the
capturing subpattern. To use backslash in replacement, it must be
doubled ("\\" PHP string).When working with a replacement pattern where a backreference is
immediately followed by another number (i.e.: placing a literal number
immediately after a matched pattern), you cannot use the familiar \1
notation for your backreference. \11, for example, would confuse
preg_replace() since it does not know whether you want the \1
backreference followed by a literal 1, or the \11 backreference
followed by nothing. In this case the solution is to use ${1}1. This
creates an isolated $1 backreference, leaving the 1 as a literal.When using the deprecated e modifier, this function escapes some
characters (namely ', ", and NULL) in the strings that replace the
This is done to ensure that no syntax errors arise
backreference usage with either single or double quotes (e.g.
'strlen('$1')+strlen("$2")'). Make sure you are aware of PHP's
string syntax to know exactly how the interpreted string will look.

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

WebStorm Mac版
好用的JavaScript開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。