Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP issue

  • 27-02-2005 01:51PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 9,447 ✭✭✭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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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