I am trying to display some text "THIS IS A TEST" on the html page.

I am getting this error:

"Notice: Undefined variable: text1 in /home/public_html/themes/videos/content.html on line 23"

Here is the php file ( I added line 35 and 39):

<?php

declare( strict_types=1);
// these should be set in PHP.ini
error_reporting(-1); // set maximum errors
ini_set('display_errors' , 'true');

if (empty($_GET['page'])) {
    header("Location: " . PT_Link('404'));
    exit();
}
$page         = PT_Secure($_GET['page']);
$limit        = 20;
$pt->rss_feed = false;
$pt->exp_feed = true;
$pages        = array(
    'trending',
    'category',
    'latest',
    'top'
);

if (!in_array($page, $pages)) {
    header("Location: " . PT_Link('404'));
    exit();
}

if (!empty($_GET['feed']) && $_GET['feed'] == 'rss') {
    $limit        = 50;
    $pt->rss_feed = true;

}

$text1 = 'THIS IS A TEST';
$cateogry_id = '';
$videos = array();
if ($page == 'trending') {
$text1 = 'trending';
    $title  = $lang->trending;
    $db->where('privacy', 0);
    $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
}

else if ($page == 'latest') {
    $title  = $lang->latest_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
}

else if ($page == 'top') {
    $title  = $lang->top_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
}

else if ($page == 'category') {
    if (!empty($_GET['id'])) {
        if (in_array($_GET['id'], array_keys($categories))) {
            $cateogry = PT_Secure($_GET['id']);
            $title    = $categories[$cateogry];
            $cateogry_id = "data-category='$cateogry'";
            $db->where('privacy', 0);
            $videos   = $db->where('category_id', $cateogry)->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
        } else {
            header("Location: " . PT_Link('404'));
            exit();
        }
    }
}

use Bhaktaraz\RSSGenerator\Item;
use Bhaktaraz\RSSGenerator\Feed;
use Bhaktaraz\RSSGenerator\Channel;

//Export rss feed
if ($pt->rss_feed) {
    $rss_feed_xml   = "";
    $fl_rss_feed    = new Feed();
    $fl_rss_channel = new Channel();

$fl_rss_channel
    ->title($pt->config->title)
    ->description($pt->config->description)
    ->url($pt->config->site_url)
    ->appendTo($fl_rss_feed);

if (is_array($videos)) {
    foreach ($videos as $feed_item_data) {
        $feed_item_data = PT_GetVideoByID($feed_item_data, 0, 0, 0);
        $fl_rss_item    = new Item();
        $fl_rss_item
         ->title($feed_item_data->title)
         ->description($feed_item_data->markup_description)
         ->url($feed_item_data->url)
         ->pubDate($feed_item_data->time)
         ->guid($feed_item_data->url,true)
         ->media(array(
            'attr'  => 'url',
            'ns'    => 'thumbnail',
            'link'  => PT_GetMedia($feed_item_data->org_thumbnail)))
         ->appendTo($fl_rss_channel);
    }
}

header('Content-type: text/rss+xml');
echo($fl_rss_feed);
exit();
}

$html_videos = '';
if (!empty($videos)) {
    foreach ($videos as $key => $video) {
        $video = PT_GetVideoByID($video, 0, 0, 0);
        $html_videos .= PT_LoadPage('videos/list', array(
            'ID' => $video->id,
            'VID_ID' => $video->id,
            'TITLE' => $video->title,
            'VIEWS' => $video->views,
            'VIEWS_NUM' => number_format($video->views),
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TIME' => $video->time_ago,
            'DURATION' => $video->duration
        ));
    }
}

if (empty($videos)) {
    $html_videos = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>' . $lang->no_videos_found_for_now . '</div>';
}
$pt->videos_count= count($videos);
$pt->page        = $page;
$pt->title       = $title . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = @$pt->config->keyword;
$pt->content     = PT_LoadPage('videos/content', array(
    'TITLE' => $title,
    'VIDEOS' => $html_videos,
    'TYPE' => $page,
    'CATEGORY_ID' => $cateogry_id
));

and here is the html file ( I added line 23):

<div class="wo_about_wrapper_parent">
    <div class="wo_about_wrapper">
        <div class="hero hero-overlay" style="background-color: #033d5d;">
            <div class="container">
                <h1 class="text-center"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video"><polygon points="23 7 16 12 23 17 23 7"></polygon><rect x="1" y="5" width="15" height="14" rx="2" ry="2"></rect></svg> {{TITLE}}</h1>
            </div>
        </div>
        <svg id="wave" viewBox="0 0 1440 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(0.000000, -564.000000)" fill="#033d5d"><g id="Head-background" transform="translate(-168.000000, -346.000000)"><g id="waves-background" transform="translate(888.000000, 934.000000) scale(-1, 1) translate(-888.000000, -934.000000) translate(168.000000, 910.000000)"><path d="M0,14.60779 C101.722445,4.7613277 195.244576,-4.14113188e-14 429,-2.84217094e-14 C732,-1.97619698e-14 798,45.6756592 1089,45.6756592 C1245.83848,45.6756592 1364.64602,29.5028807 1440,14.5904096 C1440,14.60779 1440,48 1440,48 L0,48 C0,48 0.0410082206,34 0,14.60779 Z" id="Path-3-Copy"></path></g></g></g></g></svg>
    </div>
</div>
<div class="content pt_shadow pt_page_margin" style="padding-top: 25px;">
    <div class="col-md-12">

        <div class="upload-head">
            <div style="float: right;">
                <button class="btn btn-main" data-action="multuple-buy-video" onclick="PT_MultipleBuyVideo();">View all selected</button>
            </div>
            <h4><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg></h4>
            <hr>
    </div>
 <div class="test"><font color="#696969" font size="3" face="Arial">HELLO<?php echo $text1;?></font>
</div>
        <div class="videos-latest-list row">
        {{VIDEOS}}
        </div>
        <?php if ($pt->videos_count > 1) { ?>
            <div class="watch-video-show-more desc load-more" data-type="{{TYPE}}" {{CATEGORY_ID}}>
                {{LANG show_more}}
            </div>
        <?php } ?>
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
</div>

Any additional guidance to remedy this error is appreciated.

It would be most helpful if you can help us isolate the error. Some of the tools that can help are PHP function var_dump(), and a current list of the documents without any qualifications. For example, your post says, "I added line 23" and since the post says "Undefined variable: text1 ... on line 23" we would naturally look to line 23 for the first step of the debugging process -- but neither line 23 has any reference to $text1, so we're kind of stuck. Without accurate line numbers and a faithful representation of the exact code set, there is not much chance that you can get a good answer from the community!

A good concept for questions like this is the SSCCE (google it). Then please put together an example that follows the SSCCE guidelines. Once you do that we are almost certain to be able to help!

commented: var_dump(), SSCCE, MCVE, +1 +15

From what I can see, the php file creates the variable $text1 and the html file references the variable $text1, but the html file doesn’t include the php file which has to be done with php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.