Trying to get constant from array but get literal string instead

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    Trying to get constant from array but get literal string instead

    [PHP]
    var $filterArray = array('reverse' =IMG_FILTER_NEG ATE,
    'edge highlight' =IMG_FILTER_EDG EDETECT,
    'emboss' =IMG_FILTER_EMB OSS,
    'gaussian blur' =IMG_FILTER_GAU SSIAN_BLUR,
    'blur' =IMG_FILTER_SEL ECTIVE_BLUR,
    'sketchy' =IMG_FILTER_MEA N_REMOVAL);

    [/PHP]

    I am trying to generate an HTML dropdown from this array, however, when
    I do, the value that should go in the OPTION tag literally becomes
    this:

    <option value="IMG_FILT ER_EMBOSS">embo ss</OPTION>
    Which is completely wrong; I want the actual constant IMG_FILTER_EMBO SS
    instead, which should display as an integer within the OPTION tag.

    How do I do this?

    Code:

    [PHP]
    /**
    * Generate a filter technique dropdown HTML with any additional
    features to the array before display
    *
    * *NOTE* This method will be called outside of the $this->image
    property having existence and thus will have to be used as a
    placeholder to self-instantiate using $this->self
    *
    * @access public
    * @param array $newFilterArray (optional)
    * @return mixed HTML
    */
    function &generateFilter Dropdown($newFi lterArray = '') { // STATIC
    HTML STRING METHOD
    if (!is_object($th is) || @!is_a($this,
    'ImageFilterTec hniqueGenerator ')) {
    $self =& new ImageFilterTech niqueGenerator( 'placeholder');
    } else {
    $self =& $this; // MAKE A LOCAL REFERENCE POINTER TO KEEP
    CODE CONSISTENT
    }
    if (is_array($newF ilterArray) && @sizeof($newFil terArray) 0)
    $self->setFilterArray ($newFilterArra y);
    $filterArray = $self->getFilterArray ();
    if (is_array($filt erArray) && @sizeof($filter Array) 0) {
    $html = "<select multiple name=\"filter_t ech[]\" size=\"";
    $html .= (sizeof($filter Array) 5) ? 5 : sizeof($filterA rray);
    $html .= "\">\n";
    foreach ($filterArray as $display =$filter) {
    print_r("filter = $filter = ${$filter}<P>") ; // THIS PRODUCES
    "filter = IMG_FILTER_EMBO SS =
    $html .= " <option value=\"${$filt er}\"" .
    $self->disp->preSelect(${$f ilter},
    @array_search(a rray_values($fi lterArray), ${$filter})) . '>' .
    str_replace('<' , '&lt;', str_replace('\\ ', '',
    $display)) . "</option>\n";
    }
    $html .= "</select>\n";
    }

    return $html;
    }
    [/PHP]

    Thanx
    Phil

  • bobzimuta

    #2
    Re: Trying to get constant from array but get literal string instead

    comp.lang.php wrote:
    [PHP]
    var $filterArray = array('reverse' =IMG_FILTER_NEG ATE,
    'edge highlight' =IMG_FILTER_EDG EDETECT,
    'emboss' =IMG_FILTER_EMB OSS,
    'gaussian blur' =IMG_FILTER_GAU SSIAN_BLUR,
    'blur' =IMG_FILTER_SEL ECTIVE_BLUR,
    'sketchy' =IMG_FILTER_MEA N_REMOVAL);
    >
    [/PHP]
    >
    I am trying to generate an HTML dropdown from this array, however, when
    I do, the value that should go in the OPTION tag literally becomes
    this:
    >
    <option value="IMG_FILT ER_EMBOSS">embo ss</OPTION>
    Are you using PHP 5? Those are PHP 5 constants, and if they don't exist
    the constant will be converted to that string. Just try var_dump(
    IMG_FILTER_NEGA TE ); via command line or in a script to see if the
    numeric value is returned. Otherwise, I'd try wrapping the constants
    like the following
    'reverse' =intval( IMG_FILTER_NEGA TE ),

    Comment

    • comp.lang.php

      #3
      Re: Trying to get constant from array but get literal string instead


      bobzimuta wrote:
      comp.lang.php wrote:
      [PHP]
      var $filterArray = array('reverse' =IMG_FILTER_NEG ATE,
      'edge highlight' =IMG_FILTER_EDG EDETECT,
      'emboss' =IMG_FILTER_EMB OSS,
      'gaussian blur' =IMG_FILTER_GAU SSIAN_BLUR,
      'blur' =IMG_FILTER_SEL ECTIVE_BLUR,
      'sketchy' =IMG_FILTER_MEA N_REMOVAL);

      [/PHP]

      I am trying to generate an HTML dropdown from this array, however, when
      I do, the value that should go in the OPTION tag literally becomes
      this:

      <option value="IMG_FILT ER_EMBOSS">embo ss</OPTION>
      >
      Are you using PHP 5? Those are PHP 5 constants, and if they don't exist
      the constant will be converted to that string. Just try var_dump(
      IMG_FILTER_NEGA TE ); via command line or in a script to see if the
      numeric value is returned. Otherwise, I'd try wrapping the constants
      like the following
      'reverse' =intval( IMG_FILTER_NEGA TE ),

      Thanx but I am using PHP 4.1.2 on one machine, PHP 4.3.2 on another
      machine, PHP 4.3.9 on another machine and PHP 5.0.4 on another machine,
      all test machines for building a portable web application product. So
      I can't have anything specific to PHP 5.0+ without having to come up
      with a PHP 4+ version, and I can't imagine a version for that, so I'm
      scrapping the whole filter thing.

      Thanx though
      Phil

      Comment

      Working...