How to call the php code itself?

Here is my code

    $filename = 'pesnike.txt';
    if (!$handle = fopen($filename, 'w+')) {
    echo "    '$filename'";
    %content = fread($handle, filesize($filename));
    $content = str_replace('{user_name}', ' ', $content);
    if(fwrite($handle, $content) === FALSE)  {
        echo "     '$filename'";

But how can I call it, if it is just written, there will be no sense from it?

Answer 1, authority 100%

Save to file, recall file. Either with the php filename command, or from the browser. In general, to be honest, I’m a little shocked.

And in line 7, replace %content with $content

Answer 2, authority 100%

Here’s an article to get you started, learn the basics of PHP

I will advise 2 options:

1) Option – install denver.
This is the easiest option, provided that you have a Windows OS.
On the site denwer.ruyou will find detailed instructions on installing and configuring the package.

2) Option – installing a LAMP server.
This option is more difficult, but will teach you the principles of working on a Linux system, in particular setting up a server on Linux Ubuntu.

Let’s get started:

  1. You need to download the distribution image from the developer’s site
  2. Install it where convenient. You can go to a virtual machine directly on your computer. But first, I advise you to install on a virtual machine. Set everything by default, if everything is done correctly, you will appear after rebooting the login period, enter your username and password.
  3. Let’s start installing the software.

Install apache2 + phph5 + mysql + phpmyadmin in one line

aptitude install mysql-server mysql-client libmysqlclient15-dev apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 libapache2-mod-ruby php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl phpmyadmin

This will install and configure your LAMP server.

In general, the configuration article from here, I used it many times myself!

Answer 3, authority 100%

Fix it first:




Otherwise, instead of executing the script, a code listing will be displayed :))

Answer 4

You’d better learn the basics of how php works from the beginning, rather than jumping straight into working with files. To learn and understand how to call a php script, install a web server with php support. And the first time it’s better to install everything yourself, and not use ready-made packages like xampp.