简体   繁体   中英

Cannot use php String variable in place of html plaintext

I'm having a problem with these lines of code:

<a class="button" href="javascript:unhide('<?php  $a; ?>')">Expand / Hide</a>
<?php echo substr($f2, 0, 400);?><div id="<?php $a; ?>" class = "hidden"><?php echo substr($f2, 400, 5000);?></div>

If the variable $a is replaced with plaintext then the code works, however when it links to a string variable it does not.

The example below shows an working version of the code (however because of the code's purpose I need to use a varaible):

<a class="button" href="javascript:unhide('exampleword')">Expand / Hide</a>
<?php echo substr($f2, 0, 400);?><div id="exampleword" class = "hidden"><?php echo substr($f2, 400, 5000);?>

Any ideas?

Replace

<?php  $a; ?>

with

<?php echo $a; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM