Scraping tags from an HTML page
Following code uses DOM to extract links.
Following code uses DOM to extract links.
If a string contains a single quote, it will generate an error. mysqli->real_escape_string() escapes quotes for MySQL. See example:
See the following code:
<?php
$str = 'This string has many spaces';
$str = preg_replace('/\s+/', ' ', $str);
print $str;
?>
output
This string has many spaces
Epoch time is Unix timestamp which counts the number of seconds since January 1 1970 00:00:00 UTC. Without getting into long discussion, follow is how your convert between human readable date and epoch time.
Convert Human Readable Date to Epoch Time
<?php
$now = strtotime('2010-04-25');
print $now;
?>
Convert Epoch Time to Human Readable Time
Validating email is more difficult than one might think. Recently I found this this code at PHP.net and I feel a need to republish this to emphasize its effectiveness and simplicity.
The difference between passing by value and passing by reference is that you when pass by value, you are passing a copy of the array. When passing by reference, you are passing a pointer i.e any changes made in the function you pass to can modify the original.
function foo($var) {
$var[1]++;
}
function bar(&$var) {
$var[1]++;
}
$a=array(5,6,7);
foo($a);
print "Passed by value:\n";
print_r($a);
bar($a);
print "Passed by reference:\n";
print_r($a);
output
See the following code:
<?php
$dir = 'mydir';
$myfiles = scandir($dir);
print_r($myfiles);
?>
output:
Array
(
[0] => .
[1] => ..
[2] => one.txt
[3] => two.txt
)
To remove certain file name from the list, see the following code:
Installing PHP is more than just installing the PHP source code on the system. Several libraries are also required to connect to databases, connect to GD, support XML, get LDAP access and so on. All these have to be installed manually on the machine. You can go through the painful process of manual installation and configuration or simply download and install a ready-made package from entropy.ch.
Unless you have very specific needs, you should use this package.
This error tells us that the mb_string library is not installed. mb_String mb_String is a library, which provides support for UTF-8 and UCS-2 characters. PHP uses ASCII by default which is a 256 character coding system. This means that it uses 8 bits to encode English alphabet and commonly used symbols such as ,.?;:"+-$#@ and many more. However, it does not code for foreign language characters such as é, ç, â, è, ñ, ü, and many others. mb_string provides double byte, i.e. 2 x 8bits to code for a character.
The crypt() function provide one-way encryption. Using one-way encryption is like using a key to lock and unlock something. The key is your password.
To encrypt:
$pass = 'secret';
$encrypted = crypt($pass);
// $encrypted = $1$zaxz8vXb$.lZaoK40w/EtrkkogORYo0
To decrypt: