How to parse an xml sitemap using PHP and Curl

<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ‘https://www.example.com/sitemap.xml’); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch,CURLOPT_USERAGENT,’Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36′); $resp = curl_exec ($ch); $xml = new SimpleXMLElement($resp); foreach ($xml->url…

Prevent sql injection with php

Here is a simple function to prevent Sql Injection with PHP. Just recall it and check both GET and POST parameters <?php function checkInjection() { $badchars = array("DROP", "SELECT", "UPDATE", "DELETE", "INSERT", "TRUNCATE", "UNION ALL",…

Remove script tags from string with PHP

Remove script tags (or other types of tags) from a string in PHP is really easy, here’s how: <?php $html = <<<HTML <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="https://cdn.dotmaui.com/dotmaui/css/dark.css" /> <script> alert('1') </script> <script…

Add PHP code into .html files

To process files with a .htm or .html file extension as PHP files you must add the following line to the file.htaccess (if this file does not exist, create it on the site ROOT). AddType…

Small PHP class to write log files

Here is a small class in PHP to write log files. If the file name is not specified, it will be assigned by the script. <?php class Log { private $PATH; function __construct($file_name = null)…

PHP: Some strings comparison functions

PHP is a very popular language for the development of Web sites. In our opinion, however, PHP has several gaps, including the lack of some strings comparison functions. Here are the three useful functions that,…

Extract numbers from a string with php

Often, you only need to extract numbers from a string. PHP makes life easy with the filter_var function used with FILTER_SANITIZE_NUMBER_INT. That’s how: <?php $string = ‘Sambuca has about 40 degrees’; $only_numbers = filter_var($string ,…