我有一个文本框值,我必须找出文本值中的%符号,有人能建议我怎么做吗?
我有一个包含一些值文本框,我必须确定该文本框是否包含% symbol
$camp_ttllimpression=$_POST['camp_ttllimpression'];
$camp_ttllclicks=$_POST['camp_ttllclicks'];
$camp_ttlleads=$_POST['camp_ttlleads'];
$camp_ttllsales=$_POST['camp_ttllsales'];
$hid=$_POST['hid'];
$camp_cpa_amnt=$_POST['camp_cpa_amnt'];
$camp_cpm_amnt=$_POST['camp_cpm_amnt'];
$camp_cpc_amnt=$_POST['camp_cpc_amnt'];
$camp_cpl_amnt=$_POST['camp_cpl_amnt'];
$camp_cpm_budgt=($camp_ttllimpression * $camp_cpm_amnt)/1000;
$camp_cpc_budgt=$camp_ttllclicks * $camp_cpc_amnt;
$camp_cpl_budgt=$camp_ttlleads * $camp_cpl_amnt;
$camp_cpa_budgt=$camp_ttllsales * $camp_cpa_amnt;
if($hid=="%") { echo Open;} else { echo $camp_cpa_budgt;}发布于 2012-01-30 21:53:10
将正确的密钥替换为$_POST['textfield'],因为您的问题中没有明确的密钥。不需要preg_match() --这最好通过简单的字符串操作来完成。
// To find out if it contains a % anywhere...
if (strpos($_POST['texfield'], '%') !== FALSE) {
// Contais a %
}
// To find out if it contains only a %
if ($_POST['texfield'] === '%') {
// Contains only %
}发布于 2012-01-30 21:53:52
我没有完全理解你的问题,但希望你想要这样的东西,使用strpos
if(strpos($hid,"%") !== false )
https://stackoverflow.com/questions/9064857
复制相似问题