⊗ppPmSDFCT 440 of 447 menu

Titles in Content in PHP

It is much more convenient to store the page title in the same place as its content. For this, in the content file, you can come up with some kind of command that sets the file for this page.

For example, you can do it like this:

{{ title: "page 1 title" }} <div> content 1 </div>

Let's make it so that the engine, before inserting the content, extracts the title from it and inserts it into the appropriate place in the template.

First, let's get the title from the content text:

<?php preg_match('#\{\{ title: "(.+?)" \}\}#', $content, $match); $title = $match[1]; ?>

Now, in the content text, let's remove the no longer needed command so that it doesn't appear on the page:

<?php $content = preg_replace('#\{\{ title: "(.+?)" \}\}#', '', $content); ?>

Implement titles stored in the page content in your engine.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline