Javascript in php echo

Discussion in 'JavaScript' started by Alex69, May 5, 2009.

  1. #1
    I am new to PHP / javascript and cant figure out how to put this code:

    onMouseOver="javascript:change('<b>CHANNEL DESCRIPTION:</b> <?php echo ucfirst($name);?> - <?php echo addslashes($short_details); ?>')" onMouseOut="javascript:change('<?php echo $descch; ?>')"
    Code (markup):

    inside

    <?php echo '<a href=channel.php?channelId='.$chname_f['channelId'].'&catId='.$chname_f['catId'].' HERE target=iframe><strong>'.ucfirst($chname_f['name']).'</strong></a>'; ?>
    Code (markup):
    thank you all for your help & time !
     
    Alex69, May 5, 2009 IP
  2. Alex69

    Alex69 Active Member

    Messages:
    312
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    anyone please?
     
    Alex69, May 6, 2009 IP
  3. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #3
    
    <body>
    ...
    
    <a 
        href="channel.php?channelId=<?=$chname_f['channelId']?>&catId=<?=$chname_f['catId']?>"  
        onMouseOver="javascript:change('<b>CHANNEL DESCRIPTION:</b> <?=ucfirst($name)?> - <?=addslashes($short_details)?>')" 
        onMouseOut="javascript:change('<?=$descch?>')"
        target=iframe>
            <strong><?=ucfirst($chname_f['name'])?></strong>
    </a>
    
    PHP:
    in php you can use shorthand tags like:

    <?=$foo?> is the same as <?PHP echo $foo; ?>

    careful as they may be disabled by php.ini (very unlikely).

    also, there is NO need for you to constantly end a string and concatenate it with a variable and continue it, its ineffective and annoying. use double quotes - " and it supports evaluating variables. stick arrays in { }
    
    // this will work also, not done the onmouseout.
    echo "<a href='channel.php?channelId={$chname_f['channelId']}&catId={$chname_f['catId']} onMouseOver=\"javascript:change('<b>CHANNEL DESCRIPTION:</b> " . ucfirst($name) . " - " . addslashes($short_details) . ");\" target=iframe><strong>" . ucfirst($chname_f['name']). '</strong></a>';
    
    PHP:
    this really should be in the php forum not js. also, this is awful js, you should never use inline js but thats another matter and clearly not one you are ready for yet :)
     
    dimitar christoff, May 6, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I don't code PHP but have a look here:
    http://au.php.net/echo

    The syntax:
    
    echo <<<END
    This uses the "here document" syntax to output
    multiple lines with $variable interpolation. Note
    that the here document terminator must appear on a
    line with just a semicolon. no extra whitespace!
    END;
    
    Code (markup):
    looks like it could be of use here.
     
    camjohnson95, May 6, 2009 IP
  5. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #5
    cam: this will not be effective because whereas you can use $variables within a block, you cannot call a function like ucfirst() w/o ending the block first.

    of course, he can do $varname = ucfirst($varname); and then reference $varname ...

    still, this is not a JS issue, the ghost mods need to pick this up and move it :D
     
    dimitar christoff, May 6, 2009 IP