Why do programmers hate the PHP programming language?

I had nothing to do, and I was browsing somewhere and saw a study guide on PHP programming, which inspired me deeply. We all know that PHP is a popular crawler language, especially in web development. Tai has many advantages, such as being easy to learn, supporting many functions, etc. However, PHP also has some shortcomings, such as poor code readability, prone to security vulnerabilities, etc. Therefore, some developers may not like the PHP programming language, while others like it very much. In conclusion, everyone has their own likes and preferences, and no programming language is perfect.

Insert image description here

Although not all programmers hate PHP, there are some common reasons why some people may have a negative view of PHP. I have summarized a few points:

1. Inconsistent syntax

Anyone who has used PHP knows that syntax and function naming often lack consistency. For example, some functions use underscores to separate words, while others do not. This can make it difficult to remember and use these functions.

2. Security issues

Certain features of PHP may cause security issues. For example, it allows variables of different types to be compared without explicit comparison, which can lead to unexpected behavior and security vulnerabilities.

3. Slow performance updates

Although PHP's performance has improved in recent versions, it is generally slower than other languages ​​such as Python or Java.

4. Lack of modern programming features

PHP lacks some modern programming features common in other languages ​​such as Python, Ruby, or JavaScript, such as namespaces and first-class functions.

5. Code quality varies

Due to PHP's low threshold, many beginners choose PHP as their entry-level language, which may lead to a large number of low-quality PHP codes being circulated on the Internet, affecting the overall image of PHP.

However, this does not mean that PHP is a bad language. In fact, PHP is a very good choice in many situations, especially in web development. It has a large community, tons of resources, and many excellent frameworks like Laravel and Symfony. In addition, PHP is constantly evolving and improving, and many early issues have been resolved in the latest versions.

Write a crawler program in PHP

The steps of writing a PHP crawler may involve many steps, including requesting web pages, parsing HTML, storing data, etc. Here is a basic tutorial:

1. Install the necessary libraries: First, you need to install the necessary libraries in your PHP environment. For example, you might want to use Guzzle to send HTTP requests and Symfony's DomCrawler component to parse HTML. You can use Composer to install these libraries:

composer require guzzlehttp/guzzle
composer require symfony/dom-crawler

2. Create a new PHP file: Create a new PHP file in the directory where you want to store the crawler, for examplemyspider.php.

3. Write crawler code: In the myspider.php file, you can write the following code to request a web page and parse HTML:

<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;
use Symfony\Component\DomCrawler\Crawler;
use http://jshk.com.cn/mb/reg.asp?kefu=xjy(提取IP)

$client = new Client();
$response = $client->request('GET', 'http://example.com');

$crawler = new Crawler((string)$response->getBody());
$crawler->filter('div.some-class')->each(function (Crawler $node) {
    
    
    echo $node->text()."\n";
});

4. Run the crawler: In the command line, run the following command to start your crawler:

php myspider.php

This will start your crawler, which will start crawling web pages and parsing the data.

The above is just a basic tutorial, the actual crawler may be more complex. You may need to handle issues such as login, paging, asynchronous loading, etc., or you may need to use a database to store crawled data. You can check out the official Guzzle and DomCrawler documentation for more information and tutorials.

In general, no programming language can be perfect. Just choose a programming language based on your professional knowledge and preferences. If you have better suggestions, please leave a message in the comment area to discuss together.

Guess you like

Origin blog.csdn.net/weixin_44617651/article/details/134824962