John Davidson

layout - php - dymanic title

0 comments
Message:


How to set dynamic title ?
This is my header file where i want to set title dynamically.


<!DOCTYPE html><html lang="en"><head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php $title ?></title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>

the file from where i want send title


<?php
include "layout/header.php";
include "layout/footer.php";
$title = "my title";
?>


My Answer:
You can set a dynamic title in your PHP header file by using a variable to store the title and then echoing it within the tag. Here's an example:<br /> <br /> <code>php<br /> <?php<br /> $title = "Dynamic Title Example";<br /> ?><br /> <br /> <!DOCTYPE html><br /> <html><br /> <head><br /> <title><?php echo $title; ?>


Welcome to my website


This is a dynamic title example.






In this example, the variable $title is set to "Dynamic Title Example" and then echoed within the tag. You can change the value of the $title variable dynamically based on your requirements. </div> <nav class="blog-nav nav nav-justified my-5"> <a class="nav-link-prev nav-item nav-link rounded-left" href="/john_davidson/php-is-there-a-way-to-add-margins-or-scaling-in-dompdf">Previous<i class="arrow-prev fas fa-long-arrow-alt-left"></i></a> <a class="nav-link-next nav-item nav-link rounded-right" href="/john_davidson/php-sort-multi-dimensional-array-of-number-arrays">Next<i class="arrow-next fas fa-long-arrow-alt-right"></i></a> </nav> <div class="blog-comments-section"> <h3>Rate this post</h3> <a href="/sys/rating.php?post_id=4733&vote=1" class="star"><span class="fa fa-star checked"></span></a> <a href="/sys/rating.php?post_id=4733&vote=2" class="star"><span class="fa fa-star checked"></span></a> <a href="/sys/rating.php?post_id=4733&vote=3" class="star"><span class="fa fa-star checked"></span></a> <a href="/sys/rating.php?post_id=4733&vote=4" class="star"><span class="fa fa-star"></span></a> <a href="/sys/rating.php?post_id=4733&vote=5" class="star"><span class="fa fa-star"></span></a> 3 of 5 based on 8961 votes <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Product", "aggregateRating": { "@type": "AggregateRating", "ratingValue": "3", "reviewCount": "8961" }, "description": "PHP expert solution: layout - php - dymanic title", "name": "layout - php - dymanic title", "image": "https://hayatsk.info/images/8/" } </script> <hr> <h3 id="comments">Comments</h3> <!-- div class="card"> <div class="card-body"> <b>Sergey Chizh</b> <small>on 16:32</small><br> This is some text within a card body. </div> </div --> <br> <hr> <form> <div class="form-group"> <label for="exampleFormControlTextarea1">Comment</label> <textarea style="height: 200px;" class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea> </div> <div class="row"> <div class="col"> <input type="email" class="form-control" placeholder="name@example.com"> </div> <div class="col"> <input type="text" class="form-control" placeholder="Your name"> </div> </div> <div class="form-group"><br> <button type="button" class="btn btn-primary">Post</button> </div> </form> </div><!--//blog-comments-section--> </div><!--//container--> </article> <footer class="footer text-center py-2 theme-bg-dark"> <!--/* This template is free as long as you keep the footer attribution link. If you'd like to use the template without the attribution link, you can buy the commercial license via our website: themes.3rdwavemedia.com Thank you for your support. :) */--> <small class="copyright">Developed with <span class="sr-only">love</span><i class="fas fa-heart" style="color: #fb866a;"></i> by <a href="https://hayatsk.info/sergey-chizh" target="_blank">Sergey Chizh</a></small> </footer> <div style="text-align: center;"><small> © 2024 <a href="/">Hayatsk.info</a> - Personal Blogs Platform. All Rights Reserved.<br> <a href="/sign-up"> <b>Create blog</b> </a> |  <a href="/privacy" > Privacy Policy </a> |  <a href="/privacy" > Terms & Conditions </a> |  <a href="/contact" > Contact Us </a> <br></small></div> </div><!--//main-wrapper--> <!-- Modal Subscribe --> <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Subscribe</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <h2 class="heading">PHP expert interview questions and answers</h2> <div class="intro">Welcome to my blog. Subscribe and get my latest blog post in your inbox.</div> <div class="single-form-max-width pt-3 mx-auto"> <form method="post" action="/sys/subscribe.php" class="signup-form row g-2 g-lg-2 align-items-center"> <input type="hidden" name="blog_id" value="8"> <div class="col-12 col-md-9"> <label class="sr-only" for="semail">Your email</label> <input type="email" id="semail" name="email" class="form-control me-md-1 semail" placeholder="Enter email"> </div> <div class="col-12 col-md-2"> <button type="submit" class="btn btn-primary">Subscribe</button> </div> </form><!--//signup-form--> </div><!--//single-form-max-width--> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> </div> </div> </div> </div> <!-- Modal Sign In --> <div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Sign In</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form action="/sys/sign-in.php" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="exampleInput1">E-mail</label> <input name="email" type="text" class="form-control" id="exampleInput1" aria-describedby="textHelp" value=""> </div> <div class="form-group"> <label for="exampleInput2">Password</label> <input name="password" type="password" class="form-control" id="exampleInput2" aria-describedby="textHelp" value=""> </div> <button type="submit" class="btn btn-primary">Sign In</button> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> </div> </div> </div> </div> <!-- Javascript --> <script src="/themes/blog/assets/plugins/popper.min.js"></script> <script src="/themes/blog/assets/plugins/bootstrap/js/bootstrap.min.js"></script> <!-- Page Specific JS --> <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script> <!-- Custom JS --> <script src="/themes/blog/assets/js/blog.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> <div id="cookies-alert" style="position: fixed; display: none; bottom: 0px; width: 100%; background: #000; color: #fff;"> <div class="style-cookies-block"> <center> <p> This site uses cookies and services for collecting technical data of visitors (data about IP-address, location, etc.) to ensure performance and improve the quality of service. By continuing to use our site, you automatically agree to the use of these technologies.Confirm your consent by clicking <strong>OK</strong>. If you do not agree, please leave the site.</p> <a type="button" class="btn btn-warning" onClick="acceptCookies();">OK</a><br/> <a href="https://hayatsk.info/privacy"> Privacy Policy </a><br/> </center> </div> </div> <script>if($.cookie('acceptcookies')==null){$("#cookies-alert").show();}function acceptCookies(){$.cookie('acceptcookies','yes');$("#cookies-alert").hide("slow");}</script> <script>new Image().src="https://counter.yadro.ru/hit?r"+escape(document.referrer)+((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";h"+escape(document.title.substring(0,150))+";"+Math.random();</script> <!-- Yandex.Metrika counter --> <script type="text/javascript" > (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; m[i].l=1*new Date(); for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }} k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) (window, document, "script", "https://cdn.jsdelivr.net/npm/yandex-metrica-watch/tag.js", "ym"); ym(95181114, "init", { clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true }); </script> <noscript><div><img src="https://mc.yandex.ru/watch/95181114" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- /Yandex.Metrika counter --> </body> </html>