Asked  7 Months ago    Answers:  5   Viewed   37 times

I have php file index.php

In this file to use html code I am doing:

index.php

echo '
<div>
<a class="fragment" href="">
<div>';

In href I want to put value of some php variable i.e. $url How could be done?

is this correct way?

 <a class="fragment" href="<?php echo $url; ?>">

 Answers

30

You concatenate the string by ending it and starting it again:

echo '
<div>
<a class="fragment" href="' . $url . '">
<div>';

Though I personally prefer to stop the PHP tags and start them again (if I have a lot of HTML) as my IDE won't syntax highlight the HTML as it's a string:

?>
    <div>
        <a class="fragment" href="<?php echo $url; ?>">link</a>
    </div>
<?php
Wednesday, March 31, 2021
 
Kemrop
answered 7 Months ago
40

'&B' will only set bold text for printed page headers and footers, as described in the section of the documentation entitled Setting the print header and footer of a worksheet

Formatting the content of a cell is described in the section of the documentation entitled Formatting cells, something like:

$objPHPExcel->getActiveSheet()->getCell('A1')->setValue('bold');
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

or (if your content contains actual markup) using Rich Text objects if you only want to set part of the text to bold.

$objRichText = new PHPExcel_RichText();
$objRichText->createText('This text is ');

$objBoldTextRun = $objRichText->createTextRun('bold');
$objBoldTextRun->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getCell('B1')->setValue($objRichText);

but you will need to parse your markup to convert it to a Rich Text object

Saturday, May 29, 2021
 
BrunoRamalho
answered 5 Months ago
48

Option 1. In your file.php:

<script type="text/javascript">
   var varName = "<?php echo '1'; ?>"; // global
</script>
<script type="text/javascript" src="myscript.js"></script>

Option 2. create a PHP file that returns the javascript content type externalphp

Saturday, May 29, 2021
 
dimitarvp
answered 5 Months ago
78

Try like

HTML in PHP :

echo "<a href='".$link_address."'>Link</a>";

Or even you can try like

echo "<a href='$link_address'>Link</a>";

Or you can use PHP in HTML like

PHP in HTML :

<a href="<?php echo $link_address;?>"> Link </a>
Thursday, June 17, 2021
 
rojo
answered 4 Months ago
45

Based on your screenshot of Settings (Preferences on Mac) | Editor | Language Injections.

Please delete 3rd language injection rule from the bottom (the one for "div" -- that has "IDE" in Scope column).

That rule injects HTML into div tag which tells IDE to treat all other code (even PHP) inside such tag as HTML/plain text.

Thursday, August 5, 2021
 
Nil
answered 3 Months ago
Nil
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :