我使用以下内容显示一些送货方式:
foreach ($this->shipments_shipment_rates as $shipment_shipment_rates){
if(is_array($shipment_shipment_rates)) {
foreach ($shipment_shipment_rates as $shipment_shipment_rate) {
echo str_replace('name="virtuemart_shipmentmethod_id"', 'name="virtuemart_shipmentmethod_id" onclick="return ProOPC.setshipment(this);"', $shipment_shipment_rate);
echo '<div class="clear"></div>';
}
现在,如果在第一个回声之前我做了这样的if条件:
$myvariable = echo str_replace('name="virtuemart_shipmentmethod_id"', 'name="virtuemart_shipmentmethod_id" onclick="return ProOPC.setshipment(this);"', $shipment_shipment_rate);
if (strpos ($myvariable, 3) !== false) {
echo "I found my shipping method"
}
然后就像strpos总是如此。即使在$ myvariable里面也没有价值3.任何想法?
我也可以通过这样做来隐藏运输方法:
If(my_condition_with_strpos) {
echo '<div style="display:none;">' . str_replace('name="virtuemart_shipmentmethod_id"', 'name="virtuemart_shipmentmethod_id" onclick="return ProOPC.setshipment(this);"', $shipment_shipment_rate) . '</div>'
}
提前谢谢
答案 0 :(得分:1)
您将值3搜索为整数,请参阅此示例:
<?php
$string = 'asdsad';
$myvariable = str_replace('name="virtuemart_shipmentmethod_id"', 'name="virtuemart_shipmentmethod_id" onclick="return ProOPC.setshipment(this);"', $string);
if (strpos($myvariable, '3') !== false) {
echo "I found my shipping method 1";
}
else {
echo "Not found 1";
}
$string = '3';
$myvariable = str_replace('name="virtuemart_shipmentmethod_id"', 'name="virtuemart_shipmentmethod_id" onclick="return ProOPC.setshipment(this);"', $string);
if (strpos($myvariable, '3') !== false) {
echo "<br>I found my shipping method 2";
}
else {
echo "<br>Not found 2";
}