我一直在不斷試圖爲我的語法高亮顯示適配完美的字符串匹配表達式,但現在是時候尋求幫助。PHP:正則表達式匹配以下字符串示例
<?php
if (!empty($_GET['gamertag']))
{
require_once('xbox.php');
header('Content-Type: image/png');
// Content
$xbox = new Xbox($_GET['gamertag']);
$font = 'fonts/helr65w.ttf';
// Images
$bg = @imagecreatefrompng('content/gamercard.png');
$gp = @imagecreatefrompng($xbox->Links['GamerPicture']);
$st = @imagecreatefrompng('content/star.png');
$re = Array();
if ($xbox->CanViewGames())
{
foreach($xbox->RecentGames as $key => $value)
$re[] = @imagecreatefromjpeg($value['Image']);
}
// Save Transparency
@imagesavealpha($bg, true);
@imagealphablending($bg, false);
@imagecolorallocatealpha($bg, 255, 255, 255, 127);
@imagealphablending($bg, true);
// Create Colors
$white = @imagecolorallocate($bg, 255, 255, 255);
$grey = @imagecolorallocate($bg, 128, 128, 128);
$black = @imagecolorallocate($bg, 0, 0, 0);
$orange = @imagecolorallocate($bg, 233, 171, 23);
// Write Information
for($i = 0; $i < count($re); $i++) // Recent Games
@imagecopy($bg, $re[$i], (100 + (40 * $i)), 44, 0, 0, 32, 32);
for($r = 0; $r < $xbox->Reputation; $r++) // Reputation
@imagecopy($bg, $st, (196 + ($r * 20)), 125, 0, 0, 16, 16);
@imagecopy($bg, $gp, 18, 55, 0, 0, 64, 64);
@imagettftext($bg, 14, 0, 40, 30, $black, $font, $xbox->Gamertag);
@imagettftext($bg, 14, 0, 143, 105, $black, $font, $xbox->Gamerscore);
@imagettftext($bg, 6, 0, 7, 161, $black, $font, $xbox->CurrentActivity);
@imagepng($bg);
// Destroy Images
@imagedestroy($bg);
@imagedestroy($gp);
@imagedestroy($st);
foreach($re as $game)
@imagedestroy($game);
}
else
{
print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Xbox Gamercard</title>
<script type="text/javascript">
function go()
{
var gamertag = document.getElementById("gamertag").value;
window.location.href = (gamertag + ".png");
}
</script>
</head>
<body>
<input type="text" id="gamertag" onkeydown="if (event.keyCode == 13) go();" />
<input type="button" value="Submit" onclick="go();" /><br /><br />
<a href="/projects/xbox-gamercard/ttg/" title="TTG Signature Gamercard">TTG Signature Gamercard</a>
</body>
</html>');
}
?>
我正在尋找能匹配成功''
和""
之間的所有內容的表達。
它需要忽略所有(正確)轉義的版本。 (所以''
之間的內容會忽略\'
和""
之間的內容會忽略\"
)
不要緊,哪一個是第一位的。
這裏有兩個表達式我已經嘗試:
"/'[^'\\\\]*(?:\\\\.[^'\\\\]*)*?'/"
"/'(.[^']*)'/"
舉個例子,我的意思是,StackOverflow可以正確識別我的例子中的所有字符串。 –
StackOverflow使用語法突出顯示器 – Colum
乾淨的版本(不在php字符串內):'([^ \] *。)*'(警告:未經測試,我假設\ <單個字符>轉義) – LeleDumbo