image_pdfimage_print

What are namespaces in the PHP language?

PHP for advanced users: namespaces in PHP

Dear readers of our blog! In the last article we wrote about two methods of inserting a context advertisement using the PHP language. Today we will consider PHP namespaces, using the simple examples of programming. The good news – the Namespaces are easy. To preview we’ll challenge ourselves to explain it quickly. Let’s go.

Create class in PHP.

<?php
class Foo
{
  public function doAwesomeFooThings ()
  {
  // you should write your code here
  }
}
?>

Read more

How to Mass Delete Spam in the PhpBB Forum Dashboard

How to remove all spam from the PhpBB forum

Dear readers of our blog! Many people today install and actively use the popular phpBB forum. A very important thing for them to know is how to work properly with this phpBB forum. For example they are interested how to change the head of the phpBB forum.

Today we will consider the removing of all unwanted messages from your phpBB forum by means administration control panel. Let us see what steps we should undertake in order to do it properly.

Contents

The administration phpBB dashboard

Read more

How to insert a context advertisement in the body of articles using PHP?

Inserting an ad in the body of the article using PHP

Dear visitors of the blog SoftMaker.kz. Today I would like to discuss how to insert a code of context advertisement in
the body of articles
using the PHP language (ru).

Some rules of placing advertisement in the body of articles

  1. It is no good when there are too many ads in the body of the article and it complicates the reading.
  2. Also it is not convenient when the advertisement code goes right under the title of the article and it’s hard to understand where the title and the advertisement code are. After the article’s title an ad should be inserted at least between two first paragraphs.
  3. You don’t want to insert the ad in the center of the paragraph thus breaking it into two parts. It’s better to insert a context ad between the paragraphs.
  4. It would be good if ad blocks are separated by one thousand or more characters.

 

Inserting an ad between paragraphs of the article

In order to insert a block of context ad , it is necessary to determine places for advertisement block in the body of article using the rules described above. In harmony with these rules, this is a space between the paragraphs. How to get the needed values which will indicate such places between the paragraphs?

Read more

PHP examples (example source code)

php programming

Content

  1. How to create automatic counter of record number in MySQL table using PHP?
  2. How to delete all files in a folder?
  3. Is it possible in PHP to replace blocks if…else with another conditional operation?
  4. How to delete strings from a text file using the PHP language?

How to create automatic counter of record number in MySQL table using PHP?

For this, we’ll use the following function:

<?php

// The function is designed for obtainment of record number of the table 
function get_id($tbl_dt)
{   // Do descending sorting 
    $result = mysql_query("SELECT id FROM ".$tbl_dt." ORDER BY `id` DESC");   
    $myrow = mysql_fetch_array($result);
    $num_rows = mysql_num_rows($result);
    
    // if a number of records coincide with the last id, then...
    if ($num_rows==$myrow['id'])
    {  // ...take the first element  
      //in the sampling with the highest id value ,
     // by increasing this value by a unity 
       return $myrow['id'] + 1;
       } else { // Do ascending sorting, then...
        $res1=mysql_query("SELECT id FROM ".$tbl_dt." ORDER BY `id` ASC");
        $myrow1 = mysql_fetch_array($res1);
        $i = 1;
        do // ...look for "empty" id and add a record for this id
        {
            if ($i == $myrow1['id']) {
                $i++;
                continue;
            } else {
                return $i;
            }
        }
        while ($myrow1 = mysql_fetch_array($res1));
    }
}

?>

Read more

Why does an error message appear in PHP: Cannot send session cache limiter – headers already sent?

php programming

At the writing of:

<?php
	session_start();
?>

An error message appeared:

Warning: session_start() [function.session-start]:
Cannot send session cache limiter – headers already sent (output started at X:/home/localhost/www/phpbloguser/header.html:6) in X:/home/localhost/www/phpbloguser/blocks/global.inc.phpon line 110

In php.ini it is necessary to write directive output_buffering “On” (on default – Off), see php.ini. And it will be all right! To make it works it is necessary to restart your server.

This error may appear for other reasons as well:

It is necessary to check if there is a space, tab, hyphen before “<?”.

In addition, it is necessary to start a session before any text appear in the browser’s window. Because in this case session identifier is written down in cookie files. Cookies in their turn are always installed through headers sending. The error message says that headers have ALREADY been sent.

Therefore it is necessary to check if any text appears in the browser’s window before you start a session by means of session_start()?

Your php file must be saved in UTF 8 coding (without BOM). If it is with BOM, three symbols will be  typed at the beginning of the file and this results in this error.

Examples of regular expressions in PHP

PHP Examples of the regular expressions

Content

  1. How to get a substring inside the brackets from the string?
  2. How to substitute a substring inside the brackets in a string taking the ending standing right after the closing bracket?
  3. How to get a value of variable from url using regular expression PHP?
  4. How to cut out text inside a tag?
  5. Exploding, cutting an src attribute of the img tag from the text
  6. Exploding, cutting an img tag from the text together with the attributes

Read more

How to combine PHP and JavaScript?

How to combine PHP and Java Script

Suppose you need to transfer the value of PHP variables to the JavaScript function. Let’s assign values to two variables in the following way: Read more

How to change the head of the forum phpBB?

Head of the Forum PhpBB

Dear readers of our blog! Today we will consider the theme, that is interesting to many, namely how to change the subheading and headline of your phpBB forum. Hope you will like the article and in future you won’t need to delete unwanted messages from the users of your forum. Let’s start.

Read more

How to sort a multidimensional array?

php programming

Let’s use the array “goods” of the following form:

<?php

$goods[65] = array("price" => 200, "manufacture" => "Zelina");
$goods[45] = array("price" => 400, "manufacture" => "Devyatkin");
$goods[78] = array("price" => 800, "manufacture" => "Agrarnik");
$goods[89] = array("price" => 790, "manufacture" => "Belyi Orel");

?>

Read more

Error at the transfer of values by means of the form with the POST method

Error at the transfer of values by means of the form with the POST method

Error at the transfer of values by means of the form with the POST method I needed to transfer the values by means of the form with the POST method. 
Read more