Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP issue

Options
  • 27-02-2005 1:51pm
    #1
    Registered Users Posts: 252 ✭✭


    hi

    ive got a for loop which outputs gif's on the page.
    However i want to add alt text to each of these gif's
    The alt text's are defined as here:
    DEFINE("_HEB_1", "oNE");



    here is the loop

    [PHP]
    <?php
    $pieces = explode(",", $rows->params);
    for($i=0;$i < count($pieces);$i++){
    ?>
    <img src="components/com_heb/images/<?php echo $pieces[$i];?>.gif" alt="<?php echo _HEB_ $i;?>">
    <?php
    }
    ?>

    [/PHP]



    however the alt text i get is actually _HEB_0 , _HEB_1 etc as opposed to oNE etc etc

    can anyone help?


Comments

  • Registered Users Posts: 9,196 ✭✭✭RobertFoster


    Is it because you've got a space between _HEB_ and $i - so it'd be _HEB_ 1 instead of _HEB_1?

    Also try echo("_HEB_$i");


  • Closed Accounts Posts: 1,819 ✭✭✭K!LL!@N


    I'm only guessing but i'm assuming you're trying to make a string out of _HEB_ and whatever value $i has, something like _HEB_1?

    [PHP]
    <?
    $pieces = explode(",", $rows->params);
    for($i=0;$i < count($pieces);$i++){
    ?>
    <img src="components/com_heb/images/<?=$pieces[$i]?>.gif" alt="<?=" _HEB_".$i?>">
    <?
    }
    ?>
    [/PHP]

    I think that should be ok now.

    Killian


  • Registered Users Posts: 252 ✭✭ConsultClifford


    K!LL!@N wrote:
    I'm only guessing but i'm assuming you're trying to make a string out of _HEB_ and whatever value $i has, something like _HEB_1?

    [PHP]
    <?
    $pieces = explode(",", $rows->params);
    for($i=0;$i < count($pieces);$i++){
    ?>
    <img src="components/com_heb/images/<?=$pieces[$i]?>.gif" alt="<?=" _HEB_".$i?>">
    <?
    }
    ?>
    [/PHP]

    I think that should be ok now.

    Killian


    Ya im trying to make a string out of _HEB_ and whatever value $i has - however then i want to print the text associated with that global variable.

    Your examples above only produce alt="_HEB_1" as opposed to alt="oNE"
    :confused:
    Any ideas

    Tnx


  • Registered Users Posts: 1,268 ✭✭✭hostyle




  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    why not try this
    <?php 
    $heb = array('zero', 'one', 'two'); 
    
    $pieces = explode(",", $rows->params); 
    $size = count($pieces); 
    for ($i = 0; $i < $size; $i++) { 
        echo '<img src="components/com_heb/images/' 
            . $pieces[$i] . '.gif" alt="' 
            . $heb[$i] . '">'; 
    		}
    ?> 
    


  • Advertisement
  • Registered Users Posts: 252 ✭✭ConsultClifford


    Ph3n0m wrote:
    why not try this
    <?php 
    $heb = array('zero', 'one', 'two'); 
    
    $pieces = explode(",", $rows->params); 
    $size = count($pieces); 
    for ($i = 0; $i < $size; $i++) { 
        echo '<img src="components/com_heb/images/' 
            . $pieces[$i] . '.gif" alt="' 
            . $heb[$i] . '">'; 
    		}
    ?> 
    


    nice one
    tnx


Advertisement