|
|
|
การหาคำสั่งจาก tag [cmd name=value] จะทำได้ยังไงครับ? |
|
|
|
|
|
|
|
มีโค้ดเบื้องต้นช่วยให้ครับ
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test tag cmd</title>
</head>
<body>
<h1>test tag cmd</h1>
<p>eg. [cmd screenshot=http://www.xxx.xxx/img.jpg width=500]</p>
<?php $act = ( isset($_GET['act']) ? $_GET['act'] : ""); ?>
<?php if ( $act == null ): ?>
<form method="post" action="testtagcmd.php?act=post">
<textarea name="cmd" rows="7" cols="60"><?php echo @$_POST["cmd"]; ?></textarea>
<input type="submit" value="submit" style="display:block;" />
</form>
<?php else: ?>
<a href="testtagcmd.php">back</a>
<hr />
<?php
$cmd = ( isset($_POST["cmd"]) ? $_POST["cmd"] : "");
echo "input cmd: ".htmlentities($cmd, ENT_QUOTES, "UTF-8")."<br />";
if ( $cmd != null ) {
$lookupcmd = lookupcmd($cmd);
$screenshot = $lookupcmd['screenshot'];
$width = $lookupcmd['width'];
echo "<img src=\"".$screenshot."\" width=\"".$width."\" alt=\"\" />";
}
?>
<?php endif; ?>
</body>
</html>
<?php
function lookupcmd($string) {
}
?>
|
|
|
|
|
Date :
2010-11-04 18:33:01 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้ละ
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test tag cmd</title>
</head>
<body>
<h1>test tag cmd</h1>
<p>eg. [cmd screenshot=http://www.xxx.xxx/img.jpg width=500]</p>
<?php $act = ( isset($_GET['act']) ? $_GET['act'] : ""); ?>
<?php if ( $act == null ): ?>
<form method="post" action="testtagcmd.php?act=post">
<textarea name="cmd" rows="7" cols="60"><?php echo @$_POST["cmd"]; ?></textarea>
<input type="submit" value="submit" style="display:block;" />
</form>
<?php else: ?>
<a href="testtagcmd.php">back</a>
<hr />
<?php
$cmd = ( isset($_POST["cmd"]) ? $_POST["cmd"] : "");
echo "<p><b>input cmd: ".htmlentities($cmd, ENT_QUOTES, "UTF-8")."</b></p>";
if ( $cmd != null ) {
$lkupcmd = lookupcmd($cmd);
echo "<pre>";
print_r($lkupcmd);
echo "</pre>";
if ( is_array($lkupcmd) ) {
echo "<p>\$lkupcmd is array</p>";
}
if ( isset($lkupcmd['screenshot']) ) {
echo "<p>\$lkupcmd['screenshot'] is set<br />";
echo $lkupcmd['screenshot']." = ".$lkupcmd['screenshot']['value']."<br />";
echo $lkupcmd['width']." = ".$lkupcmd['width']['value']."</p>";
} else {
echo "<p>\$lkupcmd['screenshot'] is NOT set</p>";
}
}
?>
<?php endif; ?>
</body>
</html>
<?php
function lookupcmd($string = '', $name = '') {
if ( $string == null ) {return null;}
//if ( $name == null ) {return null;}
if ( preg_match('/\[cmd (?<commands>.*)]/', $string, $out) ) {
// found as $out['commands']
$commands = preg_split('/ /', $out['commands']);
foreach ( $commands as $key => $item ) {// $item is like name=value
preg_match('/(?<name>\w+)=(?<value>.*)/', $item, $out2);
$output[$out2['name']]['value'] = $out2['value'];
}
return $output;
} else {
// not found
return null;
}
}// lookupcmd
?>
|
|
|
|
|
Date :
2010-11-05 00:57:51 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถามเอง ตอบเอง
|
|
|
|
|
Date :
2010-11-05 01:14:17 |
By :
pjgunner.com |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|