Debt Consolidation - Debt Consolidation - Submit articles - Property in Qatar - Submit articles

PDA

View Full Version : Javascript in php echo


Alex69
May 5th 2009, 2:34 pm
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; ?>')"


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>'; ?>

thank you all for your help & time !

Alex69
May 6th 2009, 1:15 am
anyone please?

dimitar christoff
May 6th 2009, 2:02 am
<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>


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>';


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 :)

camjohnson95
May 6th 2009, 2:05 am
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;


looks like it could be of use here.

dimitar christoff
May 6th 2009, 2:23 am
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