Viewed   97 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

4

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
Monday, November 14, 2022
3
<form name="add" method="post">
     <p>Age:</p>
     <select name="age">
        <option value="1_sre">23</option>
        <option value="2_sam">24</option>
        <option value="5_john">25</option>
     </select>
     <input type="submit" name="submit"/>
</form>

You will have the selected value in $_POST['age'], e.g. 1_sre. Then you will be able to split the value and get the 'stud_name'.

$stud = explode("_",$_POST['age']);
$stud_id = $stud[0];
$stud_name = $stud[1];
Tuesday, October 4, 2022
5

The usual workflow:

  1. Provide a Javascript rich-text editor for your users such as TinyMCE: http://tinymce.moxiecode.com/
  2. Grab the source generated by the RTE and filter it through HTML Purifier before saving to the database.
  3. Escape the existing HTML: <div id="myHtml" style="display: none"><?php echo htmlentities($html); ?></div>
  4. Re-populate the RTE via Javascript - in the case of TinyMCE as follows: tinyMCE.activeEditor.setContent($('#myHtml').html());

You can also load the HTML content via AJAX.

Tuesday, December 27, 2022
 
ghaag
 
4

For this to work, your other php file must simply echo some string.

randomlink.php:

<?php
echo "What came first the chicken or the egg?";
?>

index.php:

echo "<a href='";
include('go/randomlink.php');
echo "'>" . $item['stockid'] . "</a>";

hope this helps you.

Wednesday, October 26, 2022
 
4

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>
Wednesday, November 23, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :