doufu6504 2016-02-09 16:52
浏览 39
已采纳

$ mobile = table_phone(); 即使不拨打$ mobile也会立即显示

can anyone explain me why is my function value shown on a page immediately even without putting <?php echo $mobile; ?>

I just type this part:

<?php $mobile = table_phone(); ?>

and phone number gets displayed, but not where I want it. Not where I call

<?php echo $mobile; ?> 

I tried to use other function like osc_user_phone_land() which is part of the osclass core and that one is working fine, but calling for mobile_phone, which is actually part of the plugin is not working properly.

Any ideas? My coding knowledge is quite limited so it might be a super simple fix..

Here is the more of the code:

<div class="description-right">
     <?php 
        $mobile = '';      
        if($mobile == '') { $mobile = table_phone(); }      
        if($mobile == '') { $mobile = __('No phone number', 'OSCLASS'); }      
     ?> 
   <div class="mob-wrap">

     <div class="mob-top">
       <span><i class="fa fa-phone"></i><?php _e("Contact", 'OSCLASS'); ?>     </span>
     </div>

     <div class="mobile-show" rel="<?php echo $mobile; ?>">
      <span>
          <?php 
            if(strlen($mobile) > 3 and $mobile <> __('No phone number', 'OSCLASS')) {
              echo substr($mobile, 0, strlen($mobile) - 3) . 'XXX'; 
            } else {
              echo $mobile;
            }
          ?>
      </span>
     </div>     

   </div>

function from helper.php

<?php
function get_realestate_attributes(){
    $locale = osc_current_user_locale();
    $return = array('attributes','other_attributes','special','lang','tel_num');
    $detail = ModelRealEstate::newInstance()->getAttributes( osc_item_id() );
    $keys = array_keys($detail) ;
    if(count($keys) == 1 && $keys[0] == 'locale' && is_null($detail[0]['locale']) ){
        // nothing to do
        return false;
    } 

    if(@@$detail['locale'][$locale]['s_number'] != "") {
        $return['tel_num']['year'] = array(
                 'label' =>__('Telephone number', 'realestate_attributes')
                ,'value' => @@$detail['locale'][$locale]['s_number']
            );
    }
    return $return;
}


function table_phone(){ 
    $detail = get_realestate_attributes();
    if($detail['tel_num']){
    ?>     
        <span>
        <?php
            foreach($detail['tel_num'] as $item){
                echo ''.$item['value'].'';
            } 
        ?>
        </span>

    <?php
    }
}
  • 写回答

1条回答 默认 最新

  • dpv50040 2016-02-09 17:05
    关注

    Change your table_phone() method like this :

    function table_phone(){ 
        $detail = get_realestate_attributes();
        $result = '';
    
        if($detail['tel_num']) {
           foreach($detail['tel_num'] as $item){
                $result .= $item['value'];
            } 
        }
    
        return $result;
    }  
    

    Now you can do $mobile = tab_phone();, you'll not have any output.
    And when you want display it, use echo $mobile.

    Because I've removed the <span> in your method, you can juste add it manually like :

    <span><?php echo $mobile; ?></span>
    

    If you cannot change the method, use a closure like the following :

    if($mobile == '') { 
        $mobile = function() { 
            table_phone(); 
        };
    }
    

    And everywhere you call $mobile, use :

    <?php $mobile(); ?> // Result is displayed
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?