|
|
|
อยากจะแยกตัว Oparator กับ Operand ตามโค้ดนี้ |
|
|
|
|
|
|
|
ตรง explode ทำยังไงให้มันใส่ delimiter กำหนดได้หลายๆค่า
Code (PHP)
<?php
function check_ex( $s )
{
$op = array('+','-','*','/');
$num = array('0','1','2','3','4','5','6','7','8','9');
echo preg_match( '/^[0-9]+([\+\-\*\/][0-9]+)+(,[0-9]+([\+\-\*\/][0-9]+)+)*$/' , $s) ? 'ok' : 'wrong';
echo "<br>";
echo "<br>";
if (!preg_match( '/^[0-9]+([\+\-\*\/][0-9]+)+(,[0-9]+([\+\-\*\/][0-9]+)+)*$/' , $s))
{
echo"Expression Invalid";
}
else
{
echo"Expression is valid";
echo "<br>";
echo"Operand";
echo '<pre>', print_r(explode('+', $s), true),'</pre>';
echo"Operator";
echo '<pre>', print_r(explode('0', $s), true),'</pre>';
}
}
check_ex("05*65+9+8");
?>
Tag : PHP
|
|
|
|
|
|
Date :
2015-09-15 17:32:54 |
By :
meatspin |
View :
722 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|