This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function add_twitter_links ($string) | |
{ | |
$string = preg_replace(array | |
( | |
"#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", | |
"#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", | |
"/@(\w+)/", | |
"/#(\w+)/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Removing symbols | |
$example1 = "String with letters, numbers 0123456789 and symbols !@#$%¨&*()_+"; | |
echo preg_replace("/[^a-zA-Z0-9\s]/", "", $example1); // String with letters numbers 0123456789 and symbols | |
# Remove symbols, including spaces | |
$example2 = "String with letters, numbers 0123456789 and symbols !@#$%¨&*()_+"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select> | |
<option value="">Selecione</option> | |
<option value="AC">Acre</option> | |
<option value="AL">Alagoas</option> | |
<option value="AP">Amapá</option> | |
<option value="AM">Amazonas</option> | |
<option value="BA">Bahia</option> | |
<option value="CE">Ceará</option> | |
<option value="DF">Distrito Federal</option> | |
<option value="ES">Espirito Santo</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Validate usernames between 4-28 chars | |
$string = "userNaME4234432_"; | |
if (preg_match('/^[a-z\d_]{4,28}$/i', $string)) | |
echo "example 1 successful."; | |
# Validate phone numbers format (XXX)XXX-XXXX | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Function | |
function post_without_curl ($url, $data, $optional_headers = null) | |
{ | |
$params = array('http' => array | |
( | |
'method' => 'POST', | |
'content' => http_build_query($data, "", "&") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# 301 Moved Permanently (redirect) | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: http://www.domain.com/newpage.html'); | |
# 404 Page Not Found | |
header('HTTP/1.1 404 Not Found'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function is_cpf_valid ($cpf) | |
{ | |
$cpf = preg_replace("/[^0-9]/", "", $cpf); | |
$digitoUm = 0; | |
$digitoDois = 0; | |
for($i = 0, $x = 10; $i <= 8; $i++, $x--): | |
$digitoUm += $cpf[$i] * $x; | |
endfor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE `table` SET `column` = REPLACE(`column`, 'origin', 'destiny'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Exibe erros de parsing, exceto notices e warnings | |
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); | |
# Exibe erros de parsing e warnings, exceto notices | |
error_reporting(E_ALL ^ E_NOTICE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$tzList = DateTimeZone::listIdentifiers(DateTimeZone::ALL); | |
var_dump($tzList); |
OlderNewer