: .
1: preg_replace_callback (*SKIP)(*FAIL) ()
, , , , inject.
:
$regex = "~(?si)(?!<table>).*?(?=<table|</table)|<table.*?</table>(*SKIP)(*FAIL)~";
, , -, .
:
$injectedString = preg_replace_callback($regex,
function($m){return inject($text,$m[0]);},
$data);
!
$regex, , , .
$text = "<table> to
</table>not a table # 1<table> to
</table>NOT A TABLE # 2<table> to
</table>";
$regex = "~(?si)(?!<table>).*?(?=<table|</table)|<table.*?</table>(*SKIP)(*FAIL)~";
$a = preg_match_all($regex,$text,$m);
print_r($m);
: Array ( [0] => Array ( [0] => not a table # 1 [1] => NOT A TABLE # 2 ) )
, html $data , . , .
2
, .
, preg_split PREG_SPLIT_DELIM_CAPTURE.
, , preg_split, , .
. 1: split $data : : <table </table>
, , (?s)<table.*?</table>
, <table, .
, -
$tableseparator = preg_split( "~(?s)(<table.*?</table>)~", $data, -1, PREG_SPLIT_DELIM_CAPTURE );
PREG_SPLIT_DELIM_CAPTURE , , , , , . [. .] , " " "-".
. 2: $tablesparator.
if(substr($tableseparator[$i],0,6)=="<table")
<table, ( ). , , inject() .
. 3: $tableseparator ( , inject).
, , preg_split, !
, , , , .:)
preg_split PREG_SPLIT_DELIM_CAPTURE
, preg_split:
$text = "Hi@There@@Oscar@@@@";
$regex = "~(@+)~";
$a = preg_split($regex,$text,-1,PREG_SPLIT_DELIM_CAPTURE);
print_r($a);
: Array ( [0] => Hi [1] => @ [2] => There [3] => @@ [4] => Oscar [5] => @@@@ [6] => )
, ( @)? , , , .