Php 如果var=EUR不起作用,则返回图像
该代码在菜单中添加了货币切换器 但不幸的是,我没有访问MySQL数据库的权限,所以我无法将图像“标志”添加到每种货币中,然后执行它们 所以我尝试使用if语句 这是我的代码:Php 如果var=EUR不起作用,则返回图像,php,Php,该代码在菜单中添加了货币切换器 但不幸的是,我没有访问MySQL数据库的权限,所以我无法将图像“标志”添加到每种货币中,然后执行它们 所以我尝试使用if语句 这是我的代码: $currency_switcher_enable = houzez_option('currency_switcher_enable'); $is_multi_currency = houzez_option('multi_currency'); if( $currency_switcher_enable != 0 &a
$currency_switcher_enable = houzez_option('currency_switcher_enable');
$is_multi_currency = houzez_option('multi_currency');
if( $currency_switcher_enable != 0 && $is_multi_currency != 1 ) {
if (class_exists('FCC_Rates')) {
$supported_currencies = houzez_get_list_of_supported_currencies();
if (0 < count($supported_currencies)) {
$current_currency = houzez_get_wpc_current_currency();
echo '<li class="btn-price-lang btn-price">';
echo '<form id="houzez-currency-switcher-form" method="post" action="#" class="open">';
echo '<button id="houzez-selected-currency" class="btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>' . $current_currency . '</span> <i class="fa fa-sort"></i></button>';
echo '<ul id="houzez-currency-switcher-list" class="dropdown-menu" aria-labelledby="dropdown" style="display:none;">';
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
if (data-currency-code='EUR') {
echo '<img src="images/euro-flag.png"';
if (data-currency-code='TR') {
echo '<img src="images/turkish-flag.png"';
}
}
echo '</ul>';
echo '<input type="hidden" id="houzez-switch-to-currency" name="houzez_switch_to_currency" value="' . $current_currency . '" />';
echo '<input type="hidden" id="currency_switch_security" name="nonce" value="' . wp_create_nonce('houzez_currency_converter_nonce') . '"/>';
echo '</form>';
echo '</li>';
}
}
}
?>
$currency\u switcher\u enable=houzez\u选项(“currency\u switcher\u enable”);
$is_multi_currency=houzez_选项(“multi_currency”);
如果($currency\u switcher\u enable!=0&&$is\u multi\u currency!=1){
如果(存在类别(“FCC_费率”)){
$supported_currences=houzez_get_list_of_supported_currences();
如果(0<计数($U支持的货币)){
$current_current=houzez_get_wpc_current_current_current_currency();
echo';
回声';
回显“.$current_currency.”;
echo';
foreach($currency\u代码支持的\u货币){
echo'- ”.$currency\u code.
”;
if(数据货币代码='EUR'){
回声';
回声';
回声';
回声';
回音“
”;
}
}
}
?>
但它不起作用?我做错了什么?
这是原始代码:
$currency_switcher_enable = houzez_option('currency_switcher_enable');
$is_multi_currency = houzez_option('multi_currency');
if( $currency_switcher_enable != 0 && $is_multi_currency != 1 ) {
if (class_exists('FCC_Rates')) {
$supported_currencies = houzez_get_list_of_supported_currencies();
if (0 < count($supported_currencies)) {
$current_currency = houzez_get_wpc_current_currency();
echo '<li class="btn-price-lang btn-price">';
echo '<form id="houzez-currency-switcher-form" method="post" action="#" class="open">';
echo '<button id="houzez-selected-currency" class="btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>' . $current_currency . '</span> <i class="fa fa-sort"></i></button>';
echo '<ul id="houzez-currency-switcher-list" class="dropdown-menu" aria-labelledby="dropdown" style="display:none;">';
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
}
echo '</ul>';
echo '<input type="hidden" id="houzez-switch-to-currency" name="houzez_switch_to_currency" value="' . $current_currency . '" />';
echo '<input type="hidden" id="currency_switch_security" name="nonce" value="' . wp_create_nonce('houzez_currency_converter_nonce') . '"/>';
echo '</form>';
echo '</li>';
}
}
}
?>
$currency\u switcher\u enable=houzez\u选项(“currency\u switcher\u enable”);
$is_multi_currency=houzez_选项(“multi_currency”);
如果($currency\u switcher\u enable!=0&&$is\u multi\u currency!=1){
如果(存在类别(“FCC_费率”)){
$supported_currences=houzez_get_list_of_supported_currences();
如果(0<计数($U支持的货币)){
$current_current=houzez_get_wpc_current_current_current_currency();
echo';
回声';
回显“.$current_currency.”;
echo';
foreach($currency\u代码支持的\u货币){
echo'- ”.$currency\u code.
”;
}
回声“
”;
回声';
回声';
回声';
回音“ ”;
}
}
}
?>
这里有很多失败:
数据货币代码
之前不带引号的字符串或不带$var,因此您应该使用$currency\u code
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
if ($currency_code =='EUR')
echo '<img src="images/euro-flag.png"';
elseif ($currency_code == 'TR')
echo '<img src="images/turkish-flag.png"';
}
foreach($currency\u code支持的\u货币){
echo'”.$currency\u code. ”;
如果($currency_code=='EUR')
echo'您在这里有许多失败:
第一个是@kerbh0lz提到的,“=”和“=”的用途不一样。这里你的是错的
第二,如果你的第二种货币是第一种货币,那么它永远不会过去
第三,您比较的是在数据货币代码
之前不带引号的字符串或不带$var,因此您应该使用$currency\u code
试试这个:
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
if ($currency_code =='EUR')
echo '<img src="images/euro-flag.png"';
elseif ($currency_code == 'TR')
echo '<img src="images/turkish-flag.png"';
}
foreach($currency\u code支持的\u货币){
echo'”.$currency\u code. ”;
如果($currency_code=='EUR')
echo'if(数据货币代码='EUR'){
,if(数据货币代码='TR'){
:=
正在赋值,=
进行比较(该代码在PHP中是否工作?)@kerbh0lz,这应该是问题所在,PHP字符串比较的工作原理与大多数编程语言的工作原理相同,您可能希望在这些比较中使用$currency_code
而不是数据货币代码
,if(数据货币代码='TR'){
:=
正在赋值,=
进行比较(该代码在PHP中是否工作?)@kerbh0lz,这应该是问题所在,PHP字符串比较的工作原理与大多数编程语言的工作原理相同,您可能希望在这些比较中使用$currency\u code
而不是数据货币代码