Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?
$percent = substr($num, 0, ((strpos($num, '.')+1)+2)); //9.99
<?
$csv = explode("\n", file_get_contents('http://test.csv'));
foreach ($csv as $key => $line)
{
$csv[$key] = str_getcsv($line);
}
<?php
$d = 'path/to/images/';
foreach(glob($d.'*.{jpg,JPG,jpeg,JPEG,png,PNG}',GLOB_BRACE) as $file){
$imag[] = basename($file);
}
<?
$url = 'http://example.com';
$method = 'read';
if($method != 'read')
{ $html = file_get_contents($url); }
else
{ ob_start(); readfile($url); $html = ob_get_clean(); }
$doc = new DomDocument;
$doc->validateOnParse = true;
$doc->loadHtml($html);
$output = clean($doc->getElementByClass('container')->textContent);
echo $output;
<?
//wordpress-like slug
function slug($text)
{
$text = str_replace(['.','™','©','®','(',')',';',':'],'',transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC;", $text));
//return $text;
return strtolower(trim(preg_replace('~-+~', '-',preg_replace('~[^-\w]+~', '-',iconv('utf-8', 'us-ascii//TRANSLIT', $text))), '-'));
}
<?
$to = 'test@test.com';
$subject = 'The test for php mail function';
$message = 'Hello';
$headers = 'From: test@test.com' . "\r\n" .
'Reply-To: test@test.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$success = mail($to, $subject, $message, $headers);
if ( isset( $success ) )
echo 'E-mail sent to: ' . $to . '<br /> Successful mail?: <strong ' . ( $success ? 'style="color:green;">YES' : 'style="color:red;">NO' ) . '</strong>';
?>
<?php
function texto($text, $limit=8) {
$text = strip_tags($text);
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.