Php-mysql Course

This php script can be used to get and display latest subjects from PHPBB and MyBB forum.
The script reads the topics from the RSS Atom Feed generated by the PHPBB and MyBB forums, so the forum must have activated the aplication that generates the Atom /RSS feed.
This script gets and shows the link, title, content and date of the latest topics from the XML page from the URL address of the RSS feed (specified in the $file_xml variable).
- For MyBB use the Atom 1.0 feed.
You can set the number of subjects you want to display, and the maximum number of words from content.

• To Download the script, click this link: Download - Show latest forum topics (3 KB).
 
- The script is Free, without assistance. Anyway, if you have qustions you can post on: CoursesWeb.net/forum/
The script was tested with PHPBB 3.2.2 and MyBB 1.8.15 forums.

Usage

  1. Copy the code below into a php file, named "s_forum.php" (or download the script from the link above).
  2. Replace the value of the "$file_xml" variable with the URL address of the RSS feed of your forum.
  3. Copy the "s_forum.php" file on your serverul, where you have the php file in which you want to include the script.
  4. Add the following code in the php file where you want to display the latest forum topics:
    <?php include 's_forum.php'; ?>

Code of the script

<?php
// Script to show latest subjects on forum (tested with PHPBB 3.2)
// From: https://coursesweb.net/php-mysql

//HERE add the URL of the RSS feed of your phpbb forum
$file_xml ='https://coursesweb.net/forum/app.php/feed/news';

// $file_xml ='https://community.mybb.com/syndication.php?type=atom1.0'; //to test MyBB (uses atom 1.0 URL)

$nr_subj =11; //Set nr. subjects to display
$nr_cuv =23; //Set maximum number of words from content to display

//tag names to read from XML
$tags_xml = array('baza'=>'entry', 'titlu'=>'title', 'url'=>'id', 'content'=>'content', 'data'=>'updated');

//gets and parses the XML file
//returns HTML code with latest subjects
function get_last_forum($file_xml) {
 GLOBAL $nr_subj, $nr_cuv, $tags_xml;
 $re ='';

 //get page data with cUrl
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $file_xml);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
 $pg_dat = curl_exec($ch);

 if(!curl_errno($ch) && is_string($pg_dat) && strlen($pg_dat)>11 && ($obj = @simplexml_load_string($pg_dat, null, LIBXML_NOCDATA))){
 $pg_dat ='';
 $baza = $obj->{$tags_xml['baza']};
 $nr_subj = min($nr_subj, count($baza));

 for($i=0; $i<$nr_subj; $i++){
 $titlu = $baza[$i]->{$tags_xml['titlu']};
 $url = str_ireplace(['http://'. $_SERVER['SERVER_NAME'] .'/', '&'], ['', '&amp;'], $baza[$i]->{$tags_xml['url']});
 $content =strip_tags(preg_replace('#\<p\>(.*?)\</p\>#i', '', $baza[$i]->{$tags_xml['content']})); //delete <p> content and tags

 //gets and formats subjects date
 $data = $baza[$i]->{$tags_xml['data']}; 
 $data = date_parse($data);
 $data = $data['day'].'-'.$data['month'].'-'.$data['year'];

 //keep specified nr. words
 if(preg_match('/([^ ]*[ ]{0,1}){1,'.$nr_cuv.'}/i', $content, $m)) $content = $m[0] .' ..';

 $link ='<a href="'. $url. '" title="'. $titlu .'">'. $titlu. '</a> <sup>'. $data.'</sup>';
 $re .='<li>'. $link.'<div>'. $content.'</li>';
 }
 if($re !='') $re ='<ol>'.$re.'</ol>';
 }

 return $re;
}

echo get_last_forum($file_xml); //outputs the result

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which attribute is used in <a> tag for the address of the link?
src href rel
<a href="http://coursesweb.net/" title="CoursesWeb.net">CoursesWeb.net</a>
Which CSS property sets the type of the text font?
font-family text-decoration font-size
h2 {
  font-family:"Calibri",sans-serif;
}
What instruction selects all the <div> tags with class="cls"?
querySelector("div.cls") getElementsByTagName("div") querySelectorAll("div.cls")
var elm_list = document.querySelectorAll("div.cls");
var nr_elms = elm_list.length;       // number of selected items
alert(nr_elms);
Indicate the function that can be used to get the sum of values in an array.
array_sum() array_diff() array_shift()
$arr =[1, 2, 3, 4);
$arr_sum = array_sum($arr);
echo $arr_sum;       // 10
Show latest topics from PHPBB, MyBB forum - Php Script

Last accessed pages

  1. Get and Modify content of an Iframe (32494)
  2. The Mastery of Love (7690)
  3. Download HTM resources (90)
  4. HTML5 Quick Tutorial (5041)
  5. Styling HTML table with CSS (412)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (715)
  2. CSS cursor property - Custom Cursors (94)
  3. Read Excel file data in PHP - PhpExcelReader (71)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (67)
  5. PHP Unzipper - Extract Zip, Rar Archives (53)