Just get it already.
$2 and $5 are the HTML tags.
$1, $4, and $6 is everything else.
Soo.. You preg_replace the string with $1, $4, and $6.
Moderator: General Moderators
That is understandable Ziggy. But you gotta remember that he is offering his time to help you. Yes, you did say once (that I can see in reviewing this thread) that you got the Regex Coach tool. But in almost that same post you continue to ask questions about not understanding what you are doing.ziggy3000 wrote:it's not that, i have told him a lot of times, but in every post, he says regex coach about 3 times, and tells me to get it every time.
Code: Select all
$str = 'SELECT * FROM blah';
$tokens = array();
$pos = 0;
for($i=0;$e=strlen($str);$i<$e;$i++) {
if(strpos(' .,()[]',$str{$i}) !== false) {
$tokens[++$pos] = $str{$i};
$pos++;
}
if($str{$i} == '\'') {
for(;$i<$e;$i++) {
if($str{$i}=='\'' && $str{$i-1} != '\\') {
$tokens[$pos] .= $str{$i}
break;
}
$tokens[$pos] .= $str{$i};
}
$pos++;
}
if($str{$i} == '"') {
for(;$i<$e;$i++) {
if($str{$i}=='"' && $str{$i-1} != '\\') {
$tokens[$pos] .= $str{$i}
break;
}
$tokens[$pos] .= $str{$i};
}
$pos++;
}
}
$highlight = array(
'SELECT' => 'red',
'UPDATE' => 'green',
'DELETE' => 'blue'
'FROM' => 'purple',
'WHERE'=>'pink'
);
foreach($tokens as $token) {
if(isset($highlight[$token]))
print '<font color="'.$highlight[$token].'">'.$token.'</font>';
else if($token{$i} == '\'' || $token{$i} == '"')
print '<font color="orange">'.$token.'</font>';
else
print $token;
}It just makes it easier take it step-by-step. If you have it, why aren't you using it? And if you are using it, why haven't you solved your problem by now??ziggy3000 wrote:here's something that i have told you a long time ago...
I GOT REGEX COACH A LONG TIME AGO!!!!
THAT JUST TELLS YOU WHAT TO USE AS REGEX, NOT HOW TO USE IT
Code: Select all
$sql = preg_replace("'(/\*.*)(<([\w]+)>)(.*)(</\\3*>)(.*\*/)'", "<span class='comment'>$1$4$6</span>", $sql);Code: Select all
preg_match_all("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $sql, $match, PREG_SET_ORDER);Code: Select all
preg_match_all("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $sql, $match, PREG_SET_ORDER);
foreach($match as $var){
$tagb = $var[1];
$text = $var[3];
$tage = $var[4];
$sql = str_replace($tagb.$text.$tage, $text, $sql);
}Code: Select all
preg_match_all("/(/\*.*)(<([\w]+)[^>]*>)(.*)(<\/\\3>)(.*\*/)/", $sql, $match, PREG_SET_ORDER);